实验4-1-7 特殊a串数列求和(20 分)

实验4-1-7 特殊a串数列求和(20 分)

给定两个均不超过9的正整数a和n,要求编写程序求$a+aa+aaa++ \cdots+aa\cdots a$(n个a)之和。

输入格式:

输入在一行中给出不超过9的正整数a和n。

输出格式:

在一行中按照“s = 对应的和”的格式输出。

输入样例:

1
2 3

输出样例:

1
s = 246
1
2
3
4
5
6
7
8
9
10
11
12
#include<stdio.h>   
int main() {
int a,n,sum,i,t;
t=sum=0;
scanf("%d%d",&a,&n);
for(i=1;i<=n;i++){
t=t*10+a;
sum+=t;
}
printf("s = %d",sum);
return 0;
}
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×