小编RPA*_*ion的帖子

打印 10 的幂 - C 中的 Printf

我必须打印 0-19 之间的 10 的幂。问题是当我想显示第一个幂(应该是 1 )时(10^0),我只是无法强制不printf重复 0 。我只能printf在我的程序中使用一个和一个{ }块(这是主函数)。

#include <stdio.h>

int main(void) {
    int power = 19;
    for (int i = 0; i <= power; i++)
        printf("1%0*d\n",i, 0);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我的输出:

10 // this should be 1, but printf still puts 0 here
10
100
1000
10000
100000
1000000
10000000
100000000
1000000000
10000000000
100000000000
1000000000000
10000000000000
100000000000000
1000000000000000
10000000000000000
100000000000000000
1000000000000000000
10000000000000000000
Run Code Online (Sandbox Code Playgroud)

c printing printf

5
推荐指数
1
解决办法
1080
查看次数

标签 统计

c ×1

printf ×1

printing ×1