# C++ Exercises

## C++ Program to calculate (a + b + c)2.

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

```
Example:

To calculate (a + b + c)2.
Formula: (a + b + c)2=a2+b2+c2+ 2*a*b + 2*b*c + 2*c*a.
Input a=1,b=2,c=3
(a + b + c)2 =36

```
```
#include <iostream>

using namespace std;
int main()
{
int a,b,c,result;
cout<<"Enter a value :";
cin>>a;
cout<<"Enter b value :";
cin>>b;
cout<<"Enter c value :";
cin>>c;
result=a*a+b*b+c*c+2*a*b+2*b*c+2*c*a;
cout<<" Result (a+b+c)^2 = :"<```
##### Output:
```
Enter a value :2
Enter b value :3
Enter c value :4

Result (a+b+c)^2 = :81

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

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

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

Result (a+b+c)^2 = :36

```