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

Help! (Pascal)
Posted by JIm 12 Dec 2012 23:51
readln(a);
   b:=0;
   if a>=0 then
   for i:=1 to a do begin
   b:=b+i;
   end
   else
   for i:=1 downto a do begin
   b:=b+i;
   end;
   writeln(b);

Edited by author 13.12.2012 00:05
Re: Help! (Pascal)
Posted by Dmitry_GOLD 13 Dec 2012 22:33
Why not check that the number is positive or negative. You can simply like this: for i := 1 to a do begin
b : = (b + i;
end. Change and try it. Should earn. Good luck :) !
Re: Help! (Pascal)
Posted by Snoop5176 15 Dec 2012 05:06
I may be mistaken, but the program is not true, namely, in the test, when the input number 0 (a = 0), the output of your number will be 0 instead of 1 .. And this is just a linear program ... that is the sum of an arithmetic progression .. Sorry for my English :)