计算求和
求Sn=a+aa+aaa+aaaa+aaaaa的前5项之和,其中a是一个数字,
例如:2+22+222+2222+22222
#include <stdio.h>
# include <math.h>
int main()
{
int a = 0;
printf("请输入a的值:>");
scanf_s("%d", &a);
int i = 0;
int t = 0;
int sum = 0;
for (i = 1; i <= 5; i++) {
t = t * 10 + a;
sum += t;
}
printf("计算结果为:%d\n", sum);
system("pause");
return 0;
}