2020-12-10

Spelling A

7-1 Generate a power table of 3 (15 points)
Input a non-negative integer n, generate a power table 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 increasing order of 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

Matters needing attention in this question

1. The C language expression of power function pow( x, a)
Example: The fourth power of 3 is pow( 3, 4 ).
2. The power function is included in the header file #include<math.h>.
3. No & cannot appear in the expression of printf.

 #include<stdio.h>
 #include<math.h>
 main()
 {
    
    
    int n, i, s;
    scanf(" %d ", &n);
    for(i = 0; i <= n; ++i)
    {
    
    
        s = pow(3, i);
        printf("pow(3,%d) = %d\n", i, s);
    }
    return 0;
 }

Guess you like

Origin blog.csdn.net/qq_52055885/article/details/110954746