用 C 語言求立方的程式



一個值的立方僅僅是這個值乘以自身的三倍。

例如, 2 的立方為 (2*2*2) = 8。

演算法

本程式的演算法簡單易懂 -

START
   Step 1 → Take integer variable A
   Step 2 → Multiply A three times
   Step 3 → Display result as Cube
STOP

虛擬碼

可以得出如下虛擬碼 -

procedure cube( n )
   
   cube = n * n * n
   DISPPLAY cube
   
end procedure

實現

本演算法的實現如下 -

#include <stdio.h>

int main() {
   int n = 5;

   printf("Cube of %d = %d", n, (n*n*n));

   return 0;
}

輸出

程式輸出應該如下 -

Cube of 5 = 125
mathematical_programs_in_c.htm
廣告
© . All rights reserved.