Dremendo Tag Line

Input numbers and print its square in C++

cin - Question 3

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

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

Program

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

using namespace std;

int main()
{
    int a,b,c,d,e;
    cout<<"Enter 5 numbers\n";
    cin>>a>>b>>c>>d>>e;
    cout<<"Square of "<<a<<"="<<a*a<<endl;
    cout<<"Square of "<<b<<"="<<b*b<<endl;
    cout<<"Square of "<<c<<"="<<c*c<<endl;
    cout<<"Square of "<<d<<"="<<d*d<<endl;
    cout<<"Square of "<<e<<"="<<e*e<<endl;
    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