
-----------------------------------
ruscutie
Thu Jan 25, 2007 7:59 pm

addition help
-----------------------------------
i'm trying to make a code which calculates the sum of 1+2+3+4+5+6.....+98+99+100... i tried 2 make the program but it doesn't work... plzz tell me what is my mistake...



var num: int
num:= 0
for i: 1..100
num:= 0+i
end for
put num



-----------------------------------
CodeMonkey2000
Thu Jan 25, 2007 8:04 pm

RE:addition help
-----------------------------------
num should equal zero, and num shoud be increasing by i. In other words, num equals num plus i.

-----------------------------------
ruscutie
Thu Jan 25, 2007 8:13 pm

Re: addition help
-----------------------------------
thnx man

-----------------------------------
Robert
Thu Jan 25, 2007 8:21 pm

RE:addition help
-----------------------------------
And in Turing...


var num: int := 0
for i: 1..100 
    num += i
end for 
put num 


-----------------------------------
zylum
Thu Jan 25, 2007 9:56 pm

RE:addition help
-----------------------------------
or

put n * (n + 1) div 2

where n is the ending number

-----------------------------------
ruscutie
Thu Jan 25, 2007 10:18 pm

RE:addition help
-----------------------------------
thnx guyzz:-)
