Computer Science Canada arranging numbers in ascending order |
Author: | soulgnat [ Wed Jan 07, 2004 8:27 pm ] |
Post subject: | arranging numbers in ascending order |
how do you arrange numbers in ascending order? is there a set piece of code that i can use? thanx |
Author: | Skizzarz [ Wed Jan 07, 2004 8:31 pm ] | ||
Post subject: | |||
u mean like:
|
Author: | Skizzarz [ Wed Jan 07, 2004 8:33 pm ] |
Post subject: | |
or do u mean like have the user enter some numbers and you arrange them from smallest to biggest? |
Author: | soulgnat [ Wed Jan 07, 2004 8:40 pm ] |
Post subject: | wrong code |
what do you mean? the code? what does ur code exactly do? the code i was asking about was about when the user enters random numbers, you arrange the entered numbers in ascending order..how do you do that? |
Author: | Maverick [ Wed Jan 07, 2004 8:48 pm ] | ||
Post subject: | |||
Yes, they do. If your sorting random numbers then...
|
Author: | Maverick [ Thu Jan 08, 2004 10:35 am ] |
Post subject: | |
Is this what you needed? |
Author: | master-awesome [ Sun Nov 23, 2014 3:22 pm ] |
Post subject: | Re: wrong code |
soulgnat @ Wed Jan 07, 2004 8:40 pm wrote: the code i was asking about was about when the user enters random numbers, you arrange the entered numbers in ascending order..how do you do that?
![]() What you have to do is you start with some statements first to get the user to enter! Like this: Quote: var num1 : real
var num2 : real var num3 : real put "Type down three different numbers and it will arrange in ascending order!" get num1,num2,num3 Now you got the things to enter. Now the computer is pretty dumb, so you need to explain to the computer exactly how you see your code. For example: You type 1, 2, and 3. You have to tell the computer that num1, where you type 1, num2, where you type 2, and num3, where you type 3, is: Quote: if num1 < num2 and num2 < num3 then
cls put "Numbers Ascending!" put num1 put num2 put num3 end if Now that sounds great, but now let's get more complicated! You are now dealing with the user entering num1, which is 3, num2, which is 1, and num3, which 2. Sounds overwhelming. Now you would know that num2 goes first, num3 goes second, and num1 goes third. The computer doesn't know that so you need to explain to the computer exactly what you see and then, write your own common sense answer: Quote: User Output:
3 % num1 1 % num2 2 % num3 Input: if num1 > num2 and num1 > num3 and num2 < num1 and num3 < num1 and num2 < num3 then cls put "Numbers Ascending!" put num2 put num3 put num1 end if Makes logical sense right, but very time consuming. Once you finish the ascending statements, you could just copy and paste the entire code and use common sense to set it up for descending statements. |
Author: | master-awesome [ Sun Nov 23, 2014 8:12 pm ] |
Post subject: | Re: arranging numbers in ascending order |
soulgnat @ Wed Jan 07, 2004 8:27 pm wrote: how do you arrange numbers in ascending order? is there a set piece of code that i can use? thanx
There is just one major flaw in this program! It can't read equal numbers! |