In this method, we will just read an integer number and multiply it 3 times.
Consider the program:
#include <stdio.h>
int main()
{
int a,cube;
printf("Enter any integer number: ");
scanf("%d",&a);
//calculating cube
cube = (a*a*a);
printf("CUBE is: %d\n",cube);
return 0;
}
Output
Enter any integer number: 8
CUBE is: 512
2) Using pow() function
pow() is a library function of math.h header file, it is used to calculate power of any number. Here, we will use this function to find the cube of a given number.
Consider the program:
#include <stdio.h>
#include <math.h>
int main()
{
int a,cube;
printf("Enter any integer number: ");
scanf("%d",&a);
//calculating cube
cube = pow(a,3);
printf("CUBE is: %d\n",cube);
return 0;
}
Output
Enter any integer number: 8
CUBE is: 512
"This is very basic program in C programming language and will be helpful for those who started learning C programming, if you liked, please write comments..."
1) Without using pow() function
In this method, we will just read an integer number and multiply it 3 times.
Consider the program:
Output
2) Using pow() function
pow() is a library function of math.h header file, it is used to calculate power of any number. Here, we will use this function to find the cube of a given number.
Consider the program:
Output
"This is very basic program in C programming language and will be helpful for those who started learning C programming, if you liked, please write comments..."
need an explanation for this answer? contact us directly to get an explanation for this answer