Answer to Question #258300 in C++ for Asim

Question #258300

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.


  1. (a+b)^2=a^2+2ab+b^2
  2. (a-b)^2=a^2-2ab+b^2
1
Expert's answer
2021-10-29T00:54:28-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS