C Programming Code Examples C > Functions Code Examples program to find cube of a number using function program to find cube of a number using function 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. Cube of a number xnum is cube = xnum * xnum * xnum. This is easy, but we need to write a separate function for this simple statement. First assign a meaningful name to the function, say cube(). The function should accept a number whose cube is to be calculated. Hence, function definition is cube(double xnum). Finally, the function should return cube of xnum passed. Hence, return type of function should be double. After observing above points function declaration looks like double cube(double xnum); #include <stdio.h> /* Function declaration */ double cube(double xnum); int main() { int xnum; double c; /* Input number to find cube from user */ printf("Enter any number: "); scanf("%d", &xnum); c = cube(xnum); printf("Cube of %d is %.2f", xnum, c); return 0; } /** * Function to find cube of any number */ double cube(double xnum) { return (xnum * xnum * xnum); }