Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include<stdio.

h>
#include<conio.h>
void main()
{
int n, A[100],temp,j;
printf("Enter the number of elements: ");
scanf("%d", & n);

printf("Enter the %d numbers:\n",n);


for(int i=0;i<n;i++)

scanf("%d",&A[i]);
for(int i=0;i<n-1;i++)
{
int flag=0;
for( j=0;j<=n-1-i;j++)
{
if(A[j]>A[j+1])
{
temp=A[j];
A[j]=A[j+1];
A[j+1]=temp;
flag=1;
}
}
if(flag==0)
break;
}
printf("Sorted list in ascending order:\n");
for ( j = 0; j < n; j++)
printf("%d\n", A[j]);

getch();
}

You might also like