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
Post A Comment:
0 comments: