# Thread: Sorting Integers

1. ## Sorting Integers

I need to know what is the command(&how it works) to sort numbers in order (e.g. 1, 2 ,3, 6, 10 ,34 ,35, 63)
Anything would be appreciated.

2. Working in 'C'...why do u want one single command to sort....

implement any of the sorting algo.

linear sorting, quick sorting etc.

Thats the best way to learn.

3. ## Sorting Integers

I just need the code to sort numbers in order that's all. I am not an expert and how do I need which code is for which.. help anyone?

4. Here is simple code for sorting

Code:
```#include<stdio.h>

int main()
{

int a[8] = {1,22,5,4,9,6,7};
int temp =0,i=0 ,j=0;
for (i=0; i<7; i++) {
for( j=i; j<7; j++) {
if( a[i] > a[j]) {
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}

printf("\n sorted array is ");
for ( i=0; i<7; i++)
printf("\n a[%d] = %d\n ", i, a[i]);

return 0;
}```
N'joy

5. Or use the qsort function:
Code:
```#include <stdio.h>
#include <stdlib.h>

int intcmp(const void *v1, const void *v2) { return(*(int *)v1- *(int *)v2); }

int main()
{
int i, a[10] = { 9, 8, 7, -5, 99, -1, 0, 1, -9, 34 };

qsort((char *)a, sizeof(a)/sizeof(*a), sizeof(*a), intcmp);

for(i=0; i<10; i++) printf(" %d",a[i]);

return 0;
}```

6. Look, you'll need an algorithim to sort an array, you can find a lot of algorithims, an easy one to understand is Bubble sort, isn't so fast, but it's easy:

http://www-ee.eng.hawaii.edu/Courses...on2.1.2.2.html

7. Before using qsort please check whether you have the libraray for that otherwise your program won't compile.

On unix it usually come as Fortran Library routine.

( library named as libF77.a ).

8. Originally posted by gotyatech
Before using qsort please check whether you have the libraray for that otherwise your program won't compile.

On unix it usually come as Fortran Library routine.

( library named as libF77.a ).

qsort is an ANSI standard function, prototyped in stdlib.h

Popular pages Recent additions