2:50002 Compute a+aa+aaa+aa…a
Description:
Fill in the blanks in the program and do not change the statements related to input and output.
Enter a positive integer repeat (0<repeat<10), and do repeat times of the following operations:
Enter two integers a and n, compute the sum of a+aa+aaa+aa…a (the last term has n a’s).
You are required to define and call function fn(a,n) that will return aa…a (a number with n a’s). For example, fn(3,2) returns 33.
Example: (The description in parentheses)
Input
2 (repeat=2)
2 3 (a=2, n=3)
8 5 (a=8, n=5)
Output
246 (2+22+222)
98760 (8+88+888+8888+88888)
#include <stdio.h>
int main()
{
int n,a,b,i,j,t=0,sum=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d%d",&a,&b);
t = 0;
sum = 0;
for(j=0;j<b;j++)
{
t = t*10+a;
sum += t;
}
printf("%d\n",sum);
}
return 0;
}