# C++ Exercises

## C++ Program to calculate (a + b)3.

Let see the program to calculate (a + b)3..

Example:
1. To calculate (a + b)3.

2. Formula: (a + b)3 = a3 + 3*a2*b + 3*a*b2 + b3 or (a + b)3 = a3 + b3 + 3*a*b(a + b)

3. Input a=1,b=2

4. (a + b)3 =16

#include <iostream> using namespace std; int main() { int a,b,result; cout<<"Enter a value :"; cin>>a; cout<<"Enter b value :"; cin>>b; result=a*a*a + 3*a*a*b + 3*a*b*b + b*b*b ; cout<<" Result (a + b)^3 = :"<<result<<endl; return 0; }
##### Output:
Enter a value :1 Enter b value :2 Result (a + b)^3 = :27
#include <iostream> using namespace std; int main() { int a,b,result; cout<<"Enter a value :"; cin>>a; cout<<"Enter b value :"; cin>>b; result=a*a*a + b*b*b+3*a*b*(a + b) ; cout<<" Result (a + b)^3 = :"<<result<<endl; return 0; }
##### Output:
Enter a value :2 Enter b value :3 Result (a + b)^3 = :125
/* C++ Program to calculate (a+b)3 using pow() function. */ #include <iostream> using namespace std; #include <math.h> int main() { int a,b,result; cout<<"Enter a value :"; cin>>a; cout<<"Enter b value :"; cin>>b; result=pow(a,3) + 3*pow(a,2)*b + 3*a*pow(b,2) + pow(b,3) ; cout<<" Result (a + b)^3 = :"<<result<<endl; return 0; }
##### Output:
Enter a value :3 Enter b value :4 Result (a + b)^3 = :343
/* C++ Program to calculate (a+b)3 using pow() function. */ #include <iostream> using namespace std; #include <math.h> int main() { int a,b,result; cout<<"Enter a value :"; cin>>a; cout<<"Enter b value :"; cin>>b; result=pow(a,3) + pow(b,3) + 3*a*b*(a + b) ; cout<<" Result (a + b)^3 = :"<
##### Output:
Enter a value :4 Enter b value :5 Result (a + b)^3 = :729