C++ Program to calculate a^2+b^2. | C++ Program to calculate 'a' square plus 'b' square.| C ++ 'a' square plus 'b' वर्ग की गणना करने का कार्यक्रम।






















C++ Program to calculate a2+b2.

Let see the program to calculate a2+b2.


Example:
  1. To calculate a2+b2.

  2. Formula: a2+b2=(a + b)2 – 2*a*b.

  3. Declare two variables they are integer data types a, b, and store
    the result in z then declares an int data type.

  4. To declare one variable int data type and one variable float data type,
    then store result float data type.

  5. Declare two variables float data type, then store float data type.

  6. Declare a two-variable integer data types, then store variable int data
    type or float data type.

  7. Input a=2,b=3

  8. Then result=(a + b)2 – 2*a*b

  9. 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