# Putting numbers in an ascending order

Discussion in 'C' started by nathaniel, Nov 21, 2006.

1. ### nathanielNew Member

Joined:
Oct 24, 2006
Messages:
7
Likes Received:
0
Trophy Points:
0
Hey ppl

I need some help

I want to know what is the correct source code for sorting numbers

say I entered num1,num2,num3,num4 and num5 what would the correct source code be to sort them in ascending order

help plz

2. ### pradeepTeam Leader

Joined:
Apr 4, 2005
Messages:
1,645
Likes Received:
87
Trophy Points:
0
Occupation:
Programmer
Location:
Kolkata, India
Home Page:
http://blog.pradeep.net.in
Well there are lots of sorting algorithms, the easiest being Bubble Sort, which is easy to implement in any programming language.
Checkout this thread for details of a few sorting algorithms http://www.go4expert.com/showthread.php?t=337
In case, you have some trouble, G4E help is just a post away.

3. ### AztecNew Member

Joined:
May 9, 2006
Messages:
90
Likes Received:
0
Trophy Points:
0
....the easiest being Bubble Sort( but worse time complexity), which is easy to implement in any programming language.

4. ### pradeepTeam Leader

Joined:
Apr 4, 2005
Messages:
1,645
Likes Received:
87
Trophy Points:
0
Occupation:
Programmer
Location:
Kolkata, India
Home Page:
http://blog.pradeep.net.in
That's right! But, for someone who is new to sorting algorithms Bubble Sort is the easiest to understand and implement.

5. ### friendsfornirajNew Member

Joined:
Nov 24, 2006
Messages:
40
Likes Received:
0
Trophy Points:
0
Occupation:
studying

well i think selection sort isbest for beginners in dat u dont have to bother to check which is smallest
i m giving code for it
if the nos are stored in an array' a'
a=num[k]
i varies from 0 to 4 nd k varies from 1 to 5
Code:
```#include<stdio.h>
#include<conio.h>
main()
{
int a[5],t,min,i,j;   \\considering all no. entered to be integer type
printf("\n please enter 5 no")  \\here u enter your 5 numbers
for( i=0;i<5;i++)
scanf("%d",&a[i]);
\\ now the sorting part

for(i=0;i<5;i++)
for(j=i+1;j<5;j++)
if(a[i]>a[j]){t=a[i];
a[i]=a[j];
a[j]=t;
}
\\ now to print the sorted array
for(i=0;i<5;i++)
printf("\n %d"a[i]);

getch();
}```
\\ yah dats it

Last edited by a moderator: Nov 24, 2006
6. ### friendsfornirajNew Member

Joined:
Nov 24, 2006
Messages:
40
Likes Received:
0
Trophy Points:
0
Occupation:
studying
if neone has better idea please letme no