# C++ Exercises

## C++ Program to calculate (a - b)4.

Let see the program to calculate (a - b)4.

```
Example:

To calculate (a - b)4.
Formula: (a - b)4 = a4 - 4a3 + 6a2b2 - 4ab3 + b4
Input a=1,b=2
(a - b)4 =1

```
```
#include <iostream>

using namespace std;
int main(void)
{
int a,b,result;
cout<<"Enter a value :";
cin>>a;
cout<<"Enter b value :";
cin>>b;
result= a*a*a*a - 4*a*a*a*b + 6*a*a*b*b - 4*a*b*b*b + b*b*b*b ;
cout<<" Result (a - b)^4 = :"<<result<<endl;
return 0;
}

```
##### Output:
```
Enter a value :2
Enter b value :5

Result (a - b)^4 = :81

```
```
/* C++ Program to calculate (a-b)4 using pow() function. */
#include <iostream>

using namespace std;
#include <math.h>
int main(void)
{
int a,b,result;
cout<<"Enter a value :";
cin>>a;
cout<<"Enter b value :";
cin>>b;
result= pow(a,4) - 4*pow(a,3)*b + 6*pow(a,2)*pow(b,2) - 4*a*pow(b,3) + pow(b,4) ;
cout<<" Result (a - b)^4 = :"<<result<<endl;
return 0;
}

```
##### Output:
```
Enter a value :1
Enter b value :3

Result (a - b)^4 = :16

```