70,037
社区成员
发帖
与我相关
我的任务
分享#include <stdio.h>
#include <math.h>
int main ()
{
long int S=0;
int i,A,N, tmp = 0;
scanf("%d%d",&A,&N);
tmp = A;
S += tmp;
if (N >= 2 && N < 10) {
printf("S = %d + ", tmp);
for (i = 1; i < N - 1; i++) {
tmp = A * pow(10, i) + tmp;
printf("%d + ", tmp);
S += tmp;
}
tmp = A * pow(10, i) + tmp;
S += tmp;
printf("%d = %ld\n", tmp, S);
} else if (N == 1) {
printf("S = %d = %ld\n", tmp, S);
}
return 0;
}
注意分析问题的逻辑,上面的代码作为一个参考吧