Exercise 2-17 Generate a power table of 3 (15 points)
Input a non-negative integer n, generate a table of powers of 3, and output the value of 3 0
~ 3 n . The power function can be called to calculate the power of 3.
Input format:
Input a non-negative integer n in one line.
Output format:
output n+1 lines in the order of increasing power, each line format is "pow(3,i) = 3 to the power of i". The title guarantees that the output data does not exceed the range of a long integer.
Input example:
3
Output example:
pow(3,0) = 1
pow(3,1) = 3
pow(3,2) = 9
pow(3,3) = 27
Author
C Course Group
Unit
Zhejiang University
Code Length Limit
16 KB
Time limit
400 ms
Memory limit
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;
}