#include <iostream>
using namespace std;
int main(){
int num;
cout<<"Enter the number to calculate square: ";
cin>>num;
cout<<"The square of number "<<num<<" is "<<num * num<<endl;
return 0;
}
Output: Working Of The Program:
Here is the working of the program:
1. This is a C++ program that calculates the square of a number entered by the user.
2. The program starts by including the iostream library, which provides input and output operations functionality.
3. The program then declares a variable called "num" of type "int", which will be used to store the number entered by the user.
4. The program outputs a prompt asking the user to enter the number to be squared using the "cout" statement.
5. The user's input is read in using the "cin" statement and stored in the "num" variable.
6. The program then calculates the square of the number by multiplying "num" by itself and outputs the result to the user using the "cout" statement.
7. The program returns 0 to indicate successful execution and terminates.
2. The program starts by including the iostream library, which provides input and output operations functionality.
3. The program then declares a variable called "num" of type "int", which will be used to store the number entered by the user.
4. The program outputs a prompt asking the user to enter the number to be squared using the "cout" statement.
5. The user's input is read in using the "cin" statement and stored in the "num" variable.
6. The program then calculates the square of the number by multiplying "num" by itself and outputs the result to the user using the "cout" statement.
7. The program returns 0 to indicate successful execution and terminates.
No comments:
Post a Comment