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
Happy coding ;)
Example:
Input any number: 5
Output: 125
Required knowledge
Basic C programming, FunctionsProgram
/**
* 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
Enter any number: 5
Cube of 5 is 125.00
Cube of 5 is 125.00
Happy coding ;)