LAST UPDATED: MARCH 30, 2022
C++ Program To Find Cube Of Any Number Using Functions
In this tutorial, we will learn how to find the cube of any number using functions.
Program To Find Cube Of Any Number Using Functions In C++
Here, a function needs to be created that returns the cube of the entered number. It can be by multiplying the given number three times and then returning the value at the end of the function call.
#include<iostream>
using namespace std;
int main()
{
float cube(float); //Function Type is float
float num,cu;
cout<<"Enter Any Number To Find Cube :\t";
cin>>num;
cu=cube(num);
cout<<"Cube Of "<<num<<" is = "<<cu<<endl<<endl;
return 0;
}
float cube(float a)
{
float cu;
cu=a*a*a;
return(cu);
}
Enter Any Number To Find Cube : 9
Cube Of 9 is = 729
Conclusion
In this program, we are taking a number as an input from a user then the cube of a number is calculated.