Quantcast
Channel: Codeforwin
Viewing all articles
Browse latest Browse all 132

C program to find cube of a number using function

$
0
0
Write a C program to input any number from user and find cube of the given number using function. How to find cube of a given number using function in C programming.

Example:
Input any number: 5
Output: 125

Required knowledge

Basic C programming, Functions

Program


/**
* C program to find cube of any number using function
*/


#include <stdio.h>


/**
* Function to find cube of any number
* @num Number whose cube is to be calculated
*/
double cube(double num)
{
return (num * num * num);
}


int main()
{
int num;
double c;

printf("Enter any number: ");
scanf("%d", &num);

c = cube(num);

printf("Cube of %d is %.2f\n", num, c);

return 0;
}


Output
X
_
Enter any number: 5
Cube of 5 is 125.00

Happy coding ;)

Viewing all articles
Browse latest Browse all 132

Trending Articles