Write a C++ program in which users are asked to enter a number to find its cube using the function and then display it on screen.

Program Code:
#include<iostream>
using namespace std;
int number_cube(int);
int main()
{
int number, cube;
cout<<"Enter a number to calculate its cube :";

cin>>number;
cout<<endl;
cube = number_cube(number);
cout<<"The cube of the entered number is : ";
cout<<cube;
return 0;
}
int number_cube(int x)
{
int temp;
temp = x*x*x;
return temp;
}

The program code is tested on www.jdoodle.com
Output:
Enter a number to calculate its cube : 5
The cube of the entered number is : 125


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: