Followers

Wednesday, April 19, 2023

Program To Print The Cube Of Number Entered By The User

Program:

 #include <iostream>  
 using namespace std;  
 int main(){  
      int num;  
      cout<<"Enter the number to calculate cube: ";  
      cin>>num;  
      cout<<"The cube of number "<<num<<" is "<<num * num * num<<endl;  
      return 0;  
 }  

Output:
 







Working Of The Program:
Here is the working of the program:
1. The first line includes the iostream library, which is necessary for input/output operations.
2. The second line declares that we are using the standard namespace (std) in our program.
3. The main() function is the starting point of the program, which is executed when the program is run.
4. Inside the main() function, an integer variable called num is declared.
5. The next line prints the message "Enter the number to calculate cube: " to the console.
6. The user is prompted to input a value for the variable num using the cin (console input) statement.
7. The next line calculates the cube of the input number using the formula num * num * num, and prints the result to the console using cout (console output).
8. The program then returns 0, which indicates successful completion of the program.

No comments:

Post a Comment

Program to Find the Length of a String

Program: #include <iostream> using namespace std; int main() { string a; cout<<"Enter the string...