程序:
//求Sn = a + aa + aaa + aaaa + aaaaa的前5项之和,其中a是一个数字,例如:2 + 22 + 222 + 2222 + 22222
#include<stdio.h>
int main()
{
int i = 0;
int a = 0;
int sum = 0;
int num=0;
scanf("%d",&num);
for (i = 0; i < 5; i++)
{
a = a * 10 + num;
sum = sum + a;
}
printf("%d", sum);
return 0;
}
结果:
2
24690
Press any key to continue
时间: 2024-10-07 16:30:11