// Find the sum of S = a + aa + aaa + aaaa + aaaaa +......+ aaa...aaa +...
#include<stdio.h>
#include<math.h>
int main()
{
int a, i, n;
long s = 0, sum = 0;
printf("Please input the value of a and n :\n");
scanf("%d %d", &a,&n);
for (i = 0; i <= n; ++i)
{
s = s + a * (int)pow(10.0,i);
sum = s + sum;
}
printf("The sum is %ld\n", sum);
return 0;
}
Output:
Please input the value of a and n:
5 3
The sum is 6170