In this tutorial you will learn about the C program to Calculate Cube of a Number and its application with practical example.
C Program to Calculate Cube of a Number
In this tutorial, we will learn to create a C program that will Calculate the Cube of a Number in C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- For loop and its concepts in C Programming.
- Conditional Statements in C Programming.
What is a cube of a number?
The cube of any number means a number multiplied by itself 3 times. This can also be called ‘a number cubed’. The symbol for cube is ³ {the power of any is 3 for cube}.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the variables for the program. 2. Taking the input number from the user to find the cube. 3. Calculating the cube of that number. 4. Printing the result cube of that number to the user. 5. End the program. |
Program to Calculate the Cube of a Number
In this program, we will take a number in input from the user. Then we will multiply that number by itself 3 times. After that, we will print the resultant answer to the user as an output.
With the help of this program, we can cube a number.
Program code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
/* C program to find a cube of a number */ #include<stdio.h> int main() { //declaring the required variable for the program. int number, cube; //taking the input number from the user. printf(" \n Please Enter any integer Value : "); scanf("%d", &number); //calculating the cube of a number. cube = number * number * number; //Printing the output cube to the user. printf("\n Cube of a given number %d is = %d", number, cube); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- Number = it will hold the integer value.
- Cube = it will hold the integer value.
Taking input number from the user to find the cube.
Calculating the cube of that number.
Printing output cube for that given number.