How do you write a program to sort an array using selection sort?

1 answer

Answer

1115439

2026-04-17 00:45

+ Follow

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

int n,i,j,temp,a[50];

printf("Enter how many elements=");

scanf("%d",&n);

printf("Enter %d elements",n);

for(i=1;i<=n;i++)

{

scanf("%d",&a[i]);

}

for(i=1;i<=n-1;i++)

{

for(j=1;j<=n-1;j++)

{

if(a[j]>a[j+1])

{

temp=a[j];

a[j]=a[j+1];

a[j+1]=temp;

}

}

}

printf("\nSorted Array:\n");

for(i=1;i<=n;i++)

{

printf("\n%d",a[i]);

}

getch();

}

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.