|
|
вернуться в форумHelp !!How simple the (1068 Sum) is,but I'm wrong,Why? Var N,i,S,Sign:longint; begin readln(N); if N>0 then Sign:=1 else Sign:=-1; N:=Abs(N); S:=Sign*(2+N)*(N-1) div 2 ; writeln(S); readln; end. I'm fool,I misunderstood the problem. > Var N,i,S,Sign:longint; > > begin > readln(N); > if N>0 then Sign:=1 else Sign:=-1; > N:=Abs(N); > S:=Sign*(2+N)*(N-1) div 2 ; > writeln(S); > readln; > end. The Correct Program: Var N,i,S,Sign:longint; begin readln(N); if N>0 then Sign:=1 else begin N:=-N; Sign:=-1 end; S:=sign*(1+N)*N div 2; if sign<0 then S:=S+1; writeln(S); readln; end. |
|
|