[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 379: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 678: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 678: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 678: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 678: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/session.php on line 1042: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4688: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4690: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4691: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4692: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
DOEACC FORUM • View topic - OBJECT:- To Sort The Array of Given Numbers
Page 1 of 1

OBJECT:- To Sort The Array of Given Numbers

Unread postPosted: Thu May 22, 2008 6:24 pm
by rajeevmahura
/* Program to Sort The Given Array */
#include<stdio.h>
#include<conio.h>
void main()
{
int num[50],cho,i,j;
clrscr();
printf("How Many Numbers Do You Want to Sort:- ");
scanf("%d",&cho);

for(i=1;i<=cho;i++)
{
printf("Enter Any Number for num[%d]",i);
scanf("%d",&num[i]);
}

for(i=1;i<=cho;i++)
{
for(j=i;j<=cho;j++)
{
if(num[i]>num[j])
{
num[i]=num[i]+num[j];
num[j]=num[i]-num[j];
num[i]=num[i]-num[j];
}
}
}

printf("After Sorting ");

for(i=1;i<=cho;i++)
{
printf("\n%d",num[i]);
}
getch();
}


----------------------------------------------------------
Input:- How Many Numbers Do You Want to Sort:- 5
Enter Any Number for num[1] 6
Enter Any Number for num[2] 8
Enter Any Number for num[3] 5
Enter Any Number for num[4] 3
Enter Any Number for num[5] 1

Output:- After Sorting
1
3
5
6
8

Re: OBJECT:- To Sort The Array of Given Numbers

Unread postPosted: Tue Sep 01, 2009 7:08 am
by manojthesingham
/*
The above is the best approach to sort 2 numbers
let a =5 & b=3
a = a+b // a = 5+3
b = a-b // b = 8-3=5
a = a-b // a = 8-5=3
this type of sort belongs to O(n square) complexity
we need to traverse i=0 to n
j=0 to n
but best sorting algorithm is HEAP & QUICK SORT

*/