|
|
back to boardDiscussion of Problem 1068. SumWhat's wrong? Posted by Rick 3 Sep 2002 02:22 PROGRAM SUMAS (INPUT,OUTPUT); VAR SUM, W, X, Y, Z:LONGINT; BEGIN READLN(input, X); IF X>0 THEN BEGIN SUM:=0; FOR Y:=0 TO X DO SUM:=SUM+Y; WRITE(output, SUM); END ELSE IF X<=0 THEN BEGIN SUM:=0; FOR Y:=1 DOWNTO X DO SUM:=SUM+Y; WRITE(output, SUM); END; END. Re: What's wrong? > PROGRAM SUMAS (INPUT,OUTPUT); > VAR > SUM, W, X, Y, Z:LONGINT; > > BEGIN > > READLN(input, X); > IF X>0 THEN > BEGIN > SUM:=0; > FOR Y:=0 TO X DO > > SUM:=SUM+Y; > WRITE(output, SUM); > > END > ELSE IF X<=0 THEN > BEGIN > SUM:=0; > FOR Y:=1 DOWNTO X DO > > SUM:=SUM+Y; > WRITE(output, SUM); > > END; > END. I don't know Pascal, but one thing is that the condition should X<1 and X>1 and X=0 |
|
|