#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
int Compute(int a,int n);
int main()
{
int a,n;
printf("请输入a的值和n的值:\n");
scanf("%d %d",&a,&n);
printf("a+aa+aaa...+aaaaa...的值为:%d\n",Compute(a,n));
return 0;
}
int Compute(int a,int n)
{
int sum = a;
int x = a;
for(int i=1;i<n;i++)
{
x = a+x*10;
sum+=x;
}
return sum;
}
该博客介绍了一个C语言程序,用于计算从给定整数开始的连续数字(如a, a+a, a+a+a...)之和,直到指定的长度。程序通过`Compute`函数实现了这一功能,使用循环结构逐步累加数字。
4547

被折叠的 条评论
为什么被折叠?



