ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1068. Sum

What's the diference?
Posted by Oscar 16 Oct 2002 22:54
I've submited this code and I always get WA, then I changed the code
to simple for loops and got it accepted, but I'm still trying to
understand why this one does not work.

Anyone can help me?

var n, i, res, k: longint;
Begin
     read(input, n);
     if n<0 then k:=-n
     else k:= n;
     for i:= 1 to k do
         res:= res + i;
     if n = 0 then
        write(output, 1)
     else
        begin
        if n < 0 then
           write(output, (res - 1)* -1)
        else
           write(output, res);
        end;
End.