#include<stdio.h>计算数字a的前n项和 Sn=a+aa+aaa+aaaa+aaaaa
int main()
{
int a = 0;
int n = 0;
scanf("%d %d", &a, &n);
int sum = 0;
int i = 0;
//int t = a;
int ret = 0;
for (i = 0; i < n; i++)
{
//sum = sum + a;法1
//a = a * 10 + t;
ret = ret * 10 + a;
sum += ret;
}
printf("%d\n", sum);
return 0;
}
C语言学习笔记:前n项和(Sn=a+aa+aaa+aaaa)
最新推荐文章于 2024-08-25 08:15:00 发布