C语言求sn=a+aa+aaa......+a....a
时间: 2023-10-21 11:04:13 浏览: 90
c 求sn=a aa aaa ... 的值
这个问题可以回答,答案是:
#include <stdio.h>
#include <math.h>
int main()
{
int s = 0, n = 0, sum = 0;
char c;
scanf("%d %c", &n, &c);
for (int i = 0; i < n; ++i) {
s += (c - '0') * pow(10, i);
sum += s;
}
printf("%d\n", sum);
return 0;
}
阅读全文