#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int size, array[50], i, j, temp;
printf("Enter Array Size : ");
scanf("%d",&size);
printf("Enter Array Elements : ");
for(i=0; i<size; i++)
{
scanf("%d",&array[i]);
}
printf("Sorting array using selection sort...\n");
for(i=0; i<size; i++)
{
for(j=i+1; j<size; j++)
{
if(array[i]>array[j])
{
temp=array[i];
array[i]=array[j];
array[j]=temp;
}
}
}
printf("Now the Array after sorting is :\n");
for(i=0; i<size; i++)
{
printf("%d ",array[i]);
}
getch();
}
Run:
Previous Next
#include<conio.h>
void main()
{
clrscr();
int size, array[50], i, j, temp;
printf("Enter Array Size : ");
scanf("%d",&size);
printf("Enter Array Elements : ");
for(i=0; i<size; i++)
{
scanf("%d",&array[i]);
}
printf("Sorting array using selection sort...\n");
for(i=0; i<size; i++)
{
for(j=i+1; j<size; j++)
{
if(array[i]>array[j])
{
temp=array[i];
array[i]=array[j];
array[j]=temp;
}
}
}
printf("Now the Array after sorting is :\n");
for(i=0; i<size; i++)
{
printf("%d ",array[i]);
}
getch();
}
Run:
Previous Next
No comments:
Post a Comment