- Learn C By Examples Time
- Learn C by Examples - Home
- C Examples - Simple Programs
- C Examples - Loops/Iterations
- C Examples - Patterns
- C Examples - Arrays
- C Examples - Strings
- C Examples - Mathematics
- C Examples - Linked List
- C Programming Useful Resources
- Learn C By Examples - Quick Guide
- Learn C By Examples - Resources
- Learn C By Examples - Discussion
Program To Find Cube In C
Cube of a value is simply three times multiplication of the value with self.
For example, cube of 2 is (2*2*2) = 8.
Algorithm
Algorithm of this program is simple and easy −
START Step 1 → Take integer variable A Step 2 → Multiply A three times Step 3 → Display result as Cube STOP
Pseudocode
A pseudocode can be derived as −
procedure cube( n ) cube = n * n * n DISPPLAY cube end procedure
Implementation
Implementation of this algorithm is given below −
#include <stdio.h> int main() { int n = 5; printf("Cube of %d = %d", n, (n*n*n)); return 0; }
Output
Output of the program should be −
Cube of 5 = 125
mathematical_programs_in_c.htm
Advertisements