Write a C++ Program which prompts the user to enter two integer values, stores them in variable named 'a' and 'b'. calculates the following expressions and display the results on screen. Output of your program must be presentable. You must use minimum possible number of paranthesis for evaluating these expressions.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int a,b;
cout<<"\nEnter a: ";
cin>>a;
cout<<"\nEnter b:";
cin>>b;
int n1,n2;
int m1, m2;
n1=(a+b)^2;
n2=a^2+2*a*b+b^2;
m1=(a-b)^2;
m2=a^2-2*a*b+b^2;
cout<<n1<<" = "<<n2<<endl;
cout<<m1<<" = "<<m2<<endl;
return 0;
}
Comments
Leave a comment