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

Username:   Password: 
 RegisterRegister   
 How to show a sum of numbers?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
nasur27




PostPosted: Tue Jan 24, 2012 9:42 pm   Post subject: How to show a sum of numbers?

What is it you are trying to achieve?
I am trying to make a program on turing that gets a positive integer and shows the sum of numbers less than or equal to it


What is the problem you are having?
trying to display the sum of numbers
Sponsor
Sponsor
Sponsor
sponsor
Aange10




PostPosted: Tue Jan 24, 2012 10:22 pm   Post subject: RE:How to show a sum of numbers?

That's interesting.


put is usually a good command for displaying purposes.
Velocity




PostPosted: Wed Jan 25, 2012 12:00 am   Post subject: RE:How to show a sum of numbers?

get pint

For decreasing i : pint .. 1
Put pint + i
end for

Grade 1 math.
Dreadnought




PostPosted: Wed Jan 25, 2012 12:56 am   Post subject: Re: How to show a sum of numbers?

@velocity If you're going to post something saying how easy the solution is (grade 1 math), at least make sure you give a solution to the actual problem.

It was asked to print the cumulative sum of all number (I assume positive integers) less than or equal to the positive integer entered. You displayed the sum of the integer entered and each individual number less than or equal to it.

I think Reading's taught in grade 1 too. Razz

But to be on topic, to sum up these numbers you should use a for loop and a variable to serve as an accumulator (a value to which you add).

As velocity showed, you can iterate over all numbers less than or equal to a positive integer using a subrange like 1 .. maxInt .

Here's a link to a tutorial on basics of Turing you might need,
Here's a link to a tutorial on loops and for loops.
Tony




PostPosted: Wed Jan 25, 2012 1:05 am   Post subject: Re: How to show a sum of numbers?

Dreadnought @ Wed Jan 25, 2012 12:56 am wrote:
But to be on topic, to sum up these numbers you should use a for loop and a variable to serve as an accumulator (a value to which you add).

http://en.wikipedia.org/wiki/Carl_Friedrich_Gauss would disagree. There's a closed-form formula for summation of terms -- (n(n+1) / 2)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Dreadnought




PostPosted: Wed Jan 25, 2012 1:11 am   Post subject: Re: How to show a sum of numbers?

Oh ya, didn't think about that one. Thanks Tony.

Anything repetitive always tends to make me think of loops.
Velocity




PostPosted: Thu Jan 26, 2012 1:00 am   Post subject: RE:How to show a sum of numbers?

lol thanks dreadnought, i typed that from my cellphone, and was not able to test it, i suppose i had also made a grade one mistake too xd
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  [ 7 Posts ]
Jump to:   


Style:  
Search: