方法一:
#include<stdio.h>
#include<math.h>
int main()
{
int n;
double i, sum = 0, a = 0, b = 0, c = 0, d = 0;
printf("Please enter a bit:\n");
scanf("%d", &n);
for(i = 1; i <= n; i++)
{
sum += d;
c = i - 1;
b = pow(10.0, c);
a = 2 * b;
d += a;
sum += a;
}
printf("The sum is:%f\n", sum);
return 0;
}
方法二:
#include<stdio.h>
int main()
{
int i, sum = 0, n, b = 2;
printf("Please enter a bit:\n");
scanf("%d", &n);
for(i = 0; i < n; i++)
{
sum += b;
b = b * 10 + 2;
}
printf("The sum is:\n%d\n", sum);
return 0;
}
如果觉得《求Sn = a + aa + aaa + ... + aa...a(n个a)之值 其中a是一个数字 n表示a的位数 n由键盘输入》对你有帮助,请点赞、收藏,并留下你的观点哦!