Find the sum of the first 5 terms of Sn=a+aa+aaa+aaaa+aaaaa, where a is a number, for example: 2+22+222+2222+22222

#include<stdio.h>
int main()
{
int i = 0;
int sum = 0;
int n = 2;
for(i = 0; i < 5; i++)//There are five items in total, loop 5 times
{
sum += n;//Find the first i term and
n = 2 + n*10;// 2+20 2+220
}
printf("%d\n", sum);
return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324841882&siteId=291194637