C program to calculate or find cuble of a number; Through this tutorial, you will learn how to find cube of a number in the c program with the help of function, and normal formula.
Programs to Find Cube of a Number in C
Follow the following algorithm and program to find cube of a number in c:
- Algorithm to Find Cube of a Number
- C Program to Find Cube of a Number using Formula
- C Program to Find Cube of a Number using Function
Algorithm to Find Cube of a Number
Use the following algorithm to write a program to find cube of a number; as follows:
- Step 1: Start Program
- Step 2: Read the number from user and store it in a.
- Step 3: Calculate cube of number using a * a * a
- Step 4: Print cube of number
- Step 5: Stop Program
C Program to Find Cube of a Number using Formula
/* C Program to find Cube of a Number */
#include<stdio.h>
int main()
{
int number, cube;
printf(" \n Please Enter any integer Value : ");
scanf("%d", &number);
cube = number * number * number;
printf("\n Cube of a given number %d is = %d", number, cube);
return 0;
}
The output of the above c program; as follows:
Please Enter any integer Value : 10 Cube of a given number 10 is = 1000
C Program to Find Cube of a Number using Function
/* C Program to find Cube of a Number using Function */
#include<stdio.h>
int FindCube(int Number);
int main()
{
int number, cube;
printf(" \n Please Enter any integer Value : ");
scanf("%d", &number);
cube = FindCube(number);
printf("\n Cube of a given number %d is = %d", number, cube);
return 0;
}
int FindCube(int Number)
{
return Number * Number * Number;
}
The output of the above c program; as follows:
Please Enter any integer Value : 5 Cube of a given number 5 is = 125