Dremendo Tag Line

Calculate expression in C

scanf() - Question 15

In this question, we will see how to input the values in the variable a, b in C programming using the scanf() function and find the result of the expression a2+2ab+b2. To know more about scanf() function click on the scanf() function 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 <stdio.h>
#include <conio.h>

int main()
{
    int a,b,c;
    printf("Enter value of a ");
    scanf("%d",&a);
    printf("Enter value of b ");
    scanf("%d",&b);
    c=(a*a)+(2*a*b)+(b*b);
    printf("Result=%d",c);
    return 0;
}

Output

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