每日一练:求和。
/******************************************************************************************求Sn = a + aa + aaa + ... + aaaaaaa(n个a),其中a和n都从键盘上输入,如从键盘上输入2,5,那么
计算S5 = 2 + 22 + 222 + 2222 + 22222.
*******************************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
int a,n,i,tmp = 0,sum = 0;
printf("please input the a:");
scanf("%d",&a);
printf("please input the n:");
scanf("%d",&n);
for(i = 1;i <= n;i++)
{
tmp = tmp + a;
sum = sum + tmp;
a = a * 10;
}
printf("sum = %d\n",sum);
return 0;
}