Computer Science Canada

addition help

Author:  ruscutie [ Thu Jan 25, 2007 7:59 pm ]
Post subject:  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...

code:


var num: int
num:= 0
for i: 1..100
num:= 0+i
end for
put num


Author:  CodeMonkey2000 [ Thu Jan 25, 2007 8:04 pm ]
Post subject:  RE:addition help

num should equal zero, and num shoud be increasing by i. In other words, num equals num plus i.

Author:  ruscutie [ Thu Jan 25, 2007 8:13 pm ]
Post subject:  Re: addition help

thnx man

Author:  Robert [ Thu Jan 25, 2007 8:21 pm ]
Post subject:  RE:addition help

And in Turing...

code:

var num: int := 0
for i: 1..100
    num += i
end for
put num

Author:  zylum [ Thu Jan 25, 2007 9:56 pm ]
Post subject:  RE:addition help

or

code:
put n * (n + 1) div 2


where n is the ending number

Author:  ruscutie [ Thu Jan 25, 2007 10:18 pm ]
Post subject:  RE:addition help

thnx guyzz:-)


: