Description
求Sn=a+aa+aaa+…+aa…aaa(有n个a)之值,其中a是一个数字。 例如:2+22+222+2222+22222(n=5),n由键盘输入。
Input
n
Output
和
Sample Input
5
Sample Output
24690
#include <stdio.h>
#include<math.h>
main() {
int a=2,b=1,n;
long int Sn=0;
scanf("%d",&n);
while(b<=n){
Sn=Sn+a;
a=a+2*pow(10,b);
b++;
}
printf("%ld",Sn);
}