Note: Should not be used to for sorting large data.

#include < stdio.h >

#include < conio.h >

#define size 20 // size of array

void main() {
  int i, j, temp, elements[size], n;
  clrscr();
  printf("Enter the number of elements\t"); // Enter the number of total elements to be sorted
  scanf("%d", & n);
  for (i = 0; i < n; i++) {                                     // loop to get the numbers from user
    printf("Enter the element %d\t", i + 1);
    scanf("%d", & elements[i]);
  }
  for (i = 0; i < n; i++) {                                     // loop to sort
    for (j = 0; j < n; j++) {
      if (elements[i] > elements[j]) {                   // if condition is true than swap the numbers
        temp = elements[i];
        elements[i] = elements[j];
        elements[j] = temp;

      }
    }
  }

  for (i = 0; i < n; i++) {                                     // loop to show sorted numbers
    printf("%d", elements[i]);
  }
  getch();
}


faltutech

Pursuing MCA from YMCA University, Faridabad

Leave a Reply

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

Read previous post:
Find Armstrong Numbers Upto 500 (C code)

Which are armstrong numbers? Numbers whose sum of cube of digits is equal to the number itself. e.g. if we...

Close