#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;
}
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为你要输入的参数
你要给定语言吧?