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

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

Ans.

#include<stdio.h>

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

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

void main()

{

float num;

clrscr();//for clear screen

printf(“\n Enter a number: “);

scanf(“%f”,&num);

printf(“\n The cube of %f is %f”,num,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.000000 is 6859.000000

Leave a Reply

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

97 Views
%d bloggers like this: