程序代码:
#include <stdio.h> #include <math.h> #define N ((int)log10(1000000000000)) int main() { int i = 1; //几位数 long long sum = (long long)i; //1的个数 for (i = 2; i <= N; i++) { printf("%I64d\n", sum); sum += sum * 9; sum += (long long)pow(10, i-1); } sum++; //最后再加1 前面求的是1到999……的 printf("%I64d\n", sum); return 0; }