Enter a non-negative integer n
, generate a table of powers of 3, and output 3 0 — — 3 n 3^{0} ——3^{n}30——3n values. The power function can be called to calculate the power of 3.
Input format:
Input gives a non-negative integer in one line n
.
Output format:
Output n+1
lines in the order of increasing power , and the format of each line is " pow(3,i) = 3的i次幂的值
". The title guarantees that the output data does not exceed the range of a long integer.
Input sample:
3
Sample output:
pow(3,0) = 1
pow(3,1) = 3
pow(3,2) = 9
pow(3,3) = 27
Code:
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
int main() {
int i,n;
scanf("%d",&n);
long long value;
for (i=0;i<=n;i++) {
// pow()返回的类型是double
value = pow(3,i);
printf("pow(3,%d) = %lld\n",i,value);
}
return 0;
}
Submit screenshot:
Problem-solving ideas:
There are two details to pay attention to:
- The title clearly indicates that the output data is in the range of long integers, so we can define a
long long int
type of variablevalue
to receive the value of the exponentiation, and the formatting symbol for the final output is%lld
pow()
The returned data is ofdouble
type, so it is inevitable that you need to force a replacement tolld
form