Function Cube of Number in C Programming

By | June 21, 2019

“Function Cube of Number in C Programming” is a C programming language program. It uses a user defined function that receives a parameter number n. It then computes and returns cube of that number. The following image shows the source code of the programmer defined function cube() and output of this C program.

Function Cube of Number in C Programming

Function Cube of Number in C Programming

The source code of C program that uses a function cube() is shown below:

 

/*
Write a C program to use a function long cube(int n)
that receives one number and returns its cube
*/
long cube(int n); /*function prototype or declaration*/
#include<stdio.h>
int main()
{
   int num1, result;
   /* Enter one number in main() */
   printf("Enter a number =");
   scanf("%d", &num1);
   /* call the function by sending one number */
   result = cube(num1);
   printf("\nCube of %d = %li", num1,result);
   return 0;  
}
/* wrtite down function definition */

long cube(int n)
{
	int c;
	c = n * n * n;
	return c;
}

Loading

Leave a Reply

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