Write a program that reads a number from the input and displays the number raise
ID: 3120202 • Letter: W
Question
Write a program that reads a number from the input and displays the number raised to third power. Implement this in two parts: a main function for reading in the user input and displaying output, and a function called cube, which should take an int as a parameter and do the calculation. Implement the program, where the cube function utilizes pass-by-value and returns an int representing the result. Modify the definition of cube from part a) such that it utilizes pass-by-pass reference and returns void.Explanation / Answer
Dear Student
Thank you for using Chegg !!
a)
#include<iostream.h>
#include<conio.h>
int cube(int);
void main()
{
clrscr();
int n=0;
cout<<"Enter the number whose cube is requird";
cin>>n;
int c=cube(n);
cout<<"the cube of entered integer is" <<c;
getch();
}
int cube(int n)
{
int cu=0;
cu = n*n*n;
return(cu);
}
b)
#include<iostream.h>
#include<conio.h>
int cube(int &, int &);
void main()
{
clrscr();
int n=0,c=0;
cout<<"Enter the number whose cube is requird";
cin>>n;
cube(n,c);
cout<<"the cube of entered integer is" <<c;
getch();
}
int cube(int &n, int &cu)
{
cu = n*n*n;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.