/**
[C程序100例_018]
题目:
求s=a+aa+aaa+aaaa+aa...a的值,基中a是一个数字.
例如:2+22+222+2222+222222(此时有5个数相加),几
个数相加由键盘控制
分析:
关键是计算出每一项的值
*/
//程序源代码
#include <stdio.h>
int main()
{
int a,n,sum=0,i=1,j,k,temp=0;
printf("Input a and n:\n");
scanf("%d%d",&a,&n);
while(i<=n)
{
temp += a; //第i项的值
sum += temp; //前 i 的总和
temp*=10; //将第i项乘10,为后一项做准备
i++;
}
printf("%d\n",sum);
return 0;
}