Page 1 of 1

OBJECT:- To Short The Array of Given Numbers

Unread postPosted: Thu May 22, 2008 6:06 pm
by rajeevmahura
/* Program to Short 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 Short:- ");
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 Shorting ");
for(i=1;i<=cho;i++)
{
printf("\n%d",num[i]);
}
getch();
}
--------------------------------------------------------------------------------
Input:- How Many Numbers Do You Want to Short:- 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 Shorting
1
3
5
6
8 */