Dremendo Tag Line

Input numbers and print its square in C

scanf() - Question 3

In this question, we will see how to input 5 numbers in C programming using the scanf() function and print the square of each numbers on separate lines. To know more about scanf() function click on the scanf() function lesson.

Q3) Write a program in C to input 5 numbers and print the square of each numbers on separate lines.

Program

#include <stdio.h>
#include <conio.h>

int main()
{
    int a,b,c,d,e;
    printf("Enter 5 numbers\n");
    scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
    printf("Square of %d=%d\n",a,a*a);
    printf("Square of %d=%d\n",b,b*b);
    printf("Square of %d=%d\n",c,c*c);
    printf("Square of %d=%d\n",d,d*d);
    printf("Square of %d=%d\n",e,e*e);
    return 0;
}

Output

Enter 5 numbers
2
3
4
5
6
Square of 2=4
Square of 3=9
Square of 4=16
Square of 5=25
Square of 6=36
video-poster