数列求和
Time Limit: 1000MS Memory Limit: 32768KB
Submit Statistic
Problem Description
数列求和是一类常见的问题,本题有一定的代表性:
求s=a+aa+aaa+aaaa+……+aa…aa(n位)
其中,a的值由键盘输入,位数n也由键盘输入。
Input
第一行输入a的值;
第二行输入位数n。
Output
输出对n个数完成求和运算后的结果。
比如a=3,n=6时,s=3+33+333+3333+33333+333333
Example Input
3
6
Example Output
370368
Hint
Author
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int s = 0,i,n,a;
scanf("%d\n%d",&a,&n);
s = a;
int cn = a;
for(i = 1;i < n;i++)
{
a = cn + a * 10;
s = s + a;
}
printf("%d\n",s);
return 0;
}