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

Username:   Password: 
 RegisterRegister   
 arranging numbers in ascending order
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
soulgnat




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Skizzarz




PostPosted: Wed Jan 07, 2004 8:31 pm   Post subject: (No subject)

u mean like:

code:
var num : int := 0
loop
put num
num := num + 1
delay (200)
end loop
Skizzarz




PostPosted: Wed Jan 07, 2004 8:33 pm   Post subject: (No subject)

or do u mean like have the user enter some numbers and you arrange them from smallest to biggest?
soulgnat




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




PostPosted: Wed Jan 07, 2004 8:48 pm   Post subject: (No subject)

Yes, they do.
If your sorting random numbers then...
code:

var number:array 1..20 of int
var num,temp:int

%load array with random integers from 0 to 100
for i:1..20
  randint(num,0,100)
  number(i):=num
end for

%sort array in ascending order
for i:1..20
  for y:1..19
     if number(y)>=number(y+1) then%<= for descending order
        temp:=number(y)
        number(y):=number(y+1)
        number(y+1):=temp
     end if
  end for
end for
Maverick




PostPosted: Thu Jan 08, 2004 10:35 am   Post subject: (No subject)

Is this what you needed?
master-awesome




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


Very Happy Oh man! I struggled with the same question and people were making this sound overly complicated, but we are going to get to the bottom of this.

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.
master-awesome




PostPosted: 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!
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  [ 8 Posts ]
Jump to:   


Style:  
Search: