-->
Showing posts with label bubble sort. Show all posts
Showing posts with label bubble sort. Show all posts

Tuesday, May 27, 2025

c program to sort numbers in ascending order | Array examples

C Array programs

C program to sort the numbers



/*1D array to sort elements
if we have 32,12,43,22,5
after sorting, we have 5,12,22,32,43
*/
#include<stdio.h>
int main()
{
int a[5];
int i,j,temp;
for(i=0;i<=4;i++)
{
printf("enter element for location %d",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<=4;i++)
{
for(j=i+1;j<=4;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<=4;i++)
{
printf("%d\n",a[i]);
}
return 0;
}

Output:

c program to sort the numbers