PROGRAM
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int a[20],n,i,j,temp;
clrscr();
printf("\nEnter the limit of the
array:");
scanf("%d",&n);
printf("Enter the elements:");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("\nThe sorted array is:");
for(i=0;i<n;i++)
printf("%d ",a[i]);
getch();
}
OUTPUT
Enter the limit
of the array:5
Enter the
elements:8
3
5
1
9
No comments:
Post a Comment