求S=1+(1+2)+(1+2+3)+…+(1+2+3+4+…N),请从键盘输入n,求s的值。

来源:百度知道 编辑:UC知道 时间:2024/06/18 03:31:37
用pascal做,谢啦!

program plus(input,output);
var
s,a:dword;
function plus(n:word):dword;
begin
if n<>1 then begin
for a:=1 to n do
s:=s+a;
plus(n-1);
end;
end;
begin
s:=0;
readln(n);
plus(n);
writeln(s);
end.
此乃递归,我没有检查,如果有小问题请见谅

s=1 for i=1 to 20 t=0 for j=1 to i t=t+j next j s=s*t next i print s

#include <stdio.h>
void main()
{
int n;
scanf("%d",&n);
while(n>0)
{ s=(n+1)n/2;

n=n--;

s+=s;
}

printf("%d\n",s)
}
应该是对的吧 我只会C 不知道能帮到你不