In: Computer Science
write a function named as cubeCalculator that takes an integer pointer as function and return its cube value , you are required to compute the cube of a number using pointer notation , return the result as an integer value , use c++
Program in C++
#include<iostream>
using namespace std;
int cubeCalculator(int *Ptr )
{
*Ptr = *Ptr * *Ptr * *Ptr; // calculate cube of number
return *Ptr; // return cube
}
int main()
{
int number;
cout<<"Enter the number"<<endl;
cin>>number; // enter number
int cube=cubeCalculator( &number ); // call function by
reference
cout<<"Cube of number is : "<<cube;//
print cube
return 0;
}
#include<iostream>
using namespace std;
int cubeCalculator(int *Ptr )
{
*Ptr = *Ptr * *Ptr * *Ptr; // calculate cube of number
return *Ptr; // return cube
}
int main()
{
int number;
cout<<"Enter the number"<<endl;
cin>>number; // enter number
int cube=cubeCalculator( &number ); // call function by reference
cout<<"Cube of number is : "<<cube;// print cube
return 0;
}
Output 1:
Output 2: