编程实现:该程序的功能是:计算并输出 S=1+(1+20.5)+(1+20.5+30.5)+…+(1+20.5+30.5+…+n0.5)

2025-01-24 15:30:47
推荐回答(3个)
回答1:

  #include
  int main()
  {
  int i, n;
  double num, sum;

  printf("Please input a number(number >= 2): ");
 scanf("%d", &n);
  sum = 1;
   for(i=2; i<=n; i++) {
   num = 20.5;
   sum += 1;
   while(num <= i*10+0.5) {
   sum += num;
   num += 10;
   }
  }
  printf("1+(1+20.5)+(1+20.5+30.5)+…+(1+20.5+30.5+…+%g) = %g\n", n*10+0.5, sum);
  return 0;
  }

回答2:

matlab编程
function S=fun(n)
s=zeros(1,n);
s(1,1)=1;
for i=2:n
s(i)=s(i-1)+i*10+0.5;
end
S=sum(s)

调用方法
S=fun(n) %n为你要输入的参数

回答3:

你要给定语言吧?