Exercise 2-17 Generate a power table of 3 (15 points)
Enter a non-negative integer n to generate a power-of-three table of 3 and output the value of 3 ~ 3 The power function can be called to calculate the power of 3.
Input format: The
input gives a non-negative integer n on one line.
Output format:
n + 1 rows are output in increasing power order, and the format of each row is "pow (3, i) = 3 to the power of i value". The problem is to ensure that the output data does not exceed the range of long integers .
Sample input:
3
Sample output:
pow(3,0) = 1
pow(3,1) = 3
pow(3,2) = 9
pow(3,3) = 27
Code from generation to generation :
#include"stdio.h"
#include"math.h"
int main()
{
int n, i;
long result;
scanf("%d", &n);
for(i = 0;i <=n; i++)
{
result = pow(3,i);
printf("pow(3,%d) = %ld\n", i, result);
}
return 0;
}
How can I write something that is not right or wrong? Welcome to correct me! ! After all, I am also a rookie who doesn't understand anything ~~~~~~ I can't write if I don't understand, I can leave a message and ask me, I will definitely say it.