C Program to Sort Array Elements using Linear Sort

Get Certified in C Programming and Take Your Skills to the Next Level

Program 1

// PROGRAM FOR  SORTING OF ARRAY
#include<stdio.h>
#include<conio.h>
int main()
{
    int ar[500],n,i,j,temp;
    xyz:printf("\nEnter limit for array");
    scanf("%d",&n);
    if(n>500)
    {
       printf("\nInvalid limit pls enter  between 1 to 500");
        goto xyz;
    }
    printf("\nEnter elements in array");
    for (i = 0; i <n ; i++)
      scanf("%d",&ar[i]);
      for(i=0;i<n;i++)
      {
           for(j=i+1;j<n;j++)
           {
                 if(ar[j]<ar[i])
                 {
                    temp=ar[i];
                    ar[i]=ar[j];
                    ar[j]=temp;
                 }
           }
      }
      printf("\nSorted elements of array:\n");
       for (i = 0; i <n ; i++)
         printf("%d\n",ar[i]);
         return 0;
}

 

Did you like this article? If Yes, please give DataFlair 5 Stars on Google

courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *