# C++ Exercises

## C++ Program to calculate a2+b2.

Let see the program to calculate a2+b2.

```Example:
To calculate a2+b2.
Formula: a2+b2=(a + b)2 – 2*a*b.
Declare two variables they are integer data types a, b, and store
the result in z then declares an int data type.
To declare one variable int data type and one variable float data type,
then store result float data type.
Declare two variables float data type, then store float data type.
Declare a two-variable integer data types, then store variable int data
type or float data type.
Input a=2,b=3
Then result=(a + b)2 – 2*a*b
a2+b2 two numbers z=-5
```

```#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+b)*(a+b)-2*a*b;
cout<<" a^2+b^2 of two numbers :"<<result<<endl;
return 0;
}

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

a^2+b^2 of two numbers:13

```

```/* C++ Program to calculate a2+b2 using pow() funtion. */
#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+b),2))-2*a*b;
cout<<" a^2+b^2 of two numbers :"<<result<<endl;
return 0;
}

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

a^2+b^2 of two numbers:5

```