練習2-17 生成3的乘方表 (15分)
輸入一個非負整數n,生成一張3的乘方表,輸出30
~3n的值,可呼叫冪函式計算3的乘方,
輸入格式:
輸入在一行中給出一個非負整數n,
輸出格式:
按照冪的遞增順序輸出n+1行,每行格式為“pow(3,i) = 3的i次冪的值”,題目保證輸出資料不超過長整型整數的范圍,
輸入樣例:
3
輸出樣例:
pow(3,0) = 1
pow(3,1) = 3
pow(3,2) = 9
pow(3,3) = 27
作者
C課程組
單位
浙江大學
代碼長度限制
16 KB
時間限制
400 ms
記憶體限制
64 MB
#include <stdio.h>
#include <math.h>
int main() {
long int n, i;
if (scanf("%ld", &n) == 1) {
for (i = 0; i <= n; i++) {
printf("pow(3,%ld) = %ld\n", i, (long int) pow(3, i));
}
}
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/191348.html
標籤:python
上一篇:編譯不通過,不知道哪步錯了,,
