C++ program (using a function) to print its cube.

Q36. Write a program (using a function) to accept a number and print its cube.

Ans.

#include<iostream.h>

#include<conio.h>  //for clrscr()

float cube(float); //Function cube’s declaration

void main()

{

float num;

clrscr();//for clear screen

cout<<“\n Enter a number: “;

cin>>num;

cout<<“\n The cube of “<<num<<” is “<<cube(num);

}

float cube(float a)   //Function cube’s definition

{

return a*a*a;  //Function cube’s definition

}

 

Output

 

Enter a number: 19

 

The cube of 19 is 6859

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: