Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 addition help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ruscutie




PostPosted: 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

Sponsor
Sponsor
Sponsor
sponsor
CodeMonkey2000




PostPosted: 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.
ruscutie




PostPosted: Thu Jan 25, 2007 8:13 pm   Post subject: Re: addition help

thnx man
Robert




PostPosted: 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
zylum




PostPosted: 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
ruscutie




PostPosted: Thu Jan 25, 2007 10:18 pm   Post subject: RE:addition help

thnx guyzz:-)
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: