Program To Find Cube In C


Advertisements

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