Dremendo Tag Line

Calculate expression in C++

cin - Question 15

In this question, we will see how to input the values in the variable a, b in C++ programming using the cin statement and find the result of the expression a2+2ab+b2. To know more about cin statement click on the cin statement lesson.

Q15) Write a program in C++ to input the values in the variable a, b and find the result of the expression a2+2ab+b2.

Program

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    int a,b,c;
    cout<<"Enter value of a ";
    cin>>a;
    cout<<"Enter value of b ";
    cin>>b;
    c=(a*a)+(2*a*b)+(b*b);
    cout<<"Result="<<c;
    return 0;
}

Output

Enter value of a 2
Enter value of b 3
Result=25
video-poster