C Program to Sort a List of an Array Element

There are many Sorting algorithms, which sort a list of an array elements.

#include<stdio.h>
int main()
{
  int n, i, j;

  printf("Enter array range(no of array element): ");
  scanf("%d",&n);

  int  arr[n];

  printf("Enter the array element: ");

  // take input(Array elements)
  for(i=0;i<n;i++)
  {
    scanf("%d",&arr[i]);
  }

  // now, sort array elements
  for(i=0;i<n;i++)
  {
    for(j=i+1;j<n;j++)
    {
      if(arr[i]>arr[j])
      {
        int temp=arr[i];

        arr[i]=arr[j];

        arr[j]=temp;
      }
    }
  }

  // display sorted array
  printf("Sorted array elements are:\n");
  for(i=0;i<n;i++)
  {
    printf("%d\n",arr[i]);
  }

  return 0;

}

Output:-

Enter array range(no of array element): 5
Enter the array element: 90
23
5
60
40
Sorted array elements are:
5
23
40
60
90

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Similar C program using Arrays

Examples on multidimensional Array in C

2 thoughts on “C Program to Sort a List of an Array Element”

  1. Pianino Teoria

    I have wanted to post something like this on one of my blogs and this has given me an idea. Thank you.

  2. Budowa Pianina

    You are not the general blog writer, man. You certainly have something important to contribute to the World Wide Web. Such a special blog. I will return for more.

Leave a Comment

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