//Program for selection sort
#include<stdio.h>
#include<conio.h>
//Main function
void main()
{
int a[10],n,i,temp,j;
clrscr();
printf("Enter size of array:");
scanf("%d",&n);
printf("\nEnter the elements into array:");
i=0;
while(i<n)
{
scanf(" %d ",&a[i]);
i++;
}
printf("\nEntered array: ");
for(i=0;i<n;i++)
{
printf("%d\t",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("\n\nSorted list: ");
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
getch();
}//end of main
/*Output
Enter size of array:5
Enter the elements into array:54 23 99 11 87
Entered array: 54 23 99 11 87
Sorted list: 11 23 54 87 99 */
#include<stdio.h>
#include<conio.h>
//Main function
void main()
{
int a[10],n,i,temp,j;
clrscr();
printf("Enter size of array:");
scanf("%d",&n);
printf("\nEnter the elements into array:");
i=0;
while(i<n)
{
scanf(" %d ",&a[i]);
i++;
}
printf("\nEntered array: ");
for(i=0;i<n;i++)
{
printf("%d\t",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("\n\nSorted list: ");
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
}
getch();
}//end of main
/*Output
Enter size of array:5
Enter the elements into array:54 23 99 11 87
Entered array: 54 23 99 11 87
Sorted list: 11 23 54 87 99 */
Pankaj Gaikar is a
professional blogger
from Pune, India who writes on Technology, Android,
Gadgets, social media and latest tech updates at
Punk Tech
,
Being Android
&
Shake The Tech
. Email me
HERE
0 comments :
Post a Comment