Advertisement
Kaidul

Raisul

Oct 14th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. int main()
  4. {
  5.     //clrscr();
  6.     // array for storing given data
  7.     int array[10];
  8.     // auxiliary variables
  9.     int i, j, temp;
  10.     //taking input
  11.     for (i = 0; i < 5; i++) {
  12.         scanf("%d", &array[i]);
  13.     }
  14.     //sorting in descending order(this sorting algorithm is known as Bubble sort. It is most easiest sorting technique to implement for beginners/novices)
  15.     for (i = 0; i < 5; i++) {
  16.         for (j = i + 1; j < 5; j++) {
  17.             // here "<" sign sorts this array in descending order. if you change it ">", it will sort in ascending order
  18.             if (array[i] < array[j]) {
  19.                 // below three lines are for swaping value i.e. a = 2, b = 4 after swaping a = 4, b = 2
  20.                 temp = array[i];
  21.                 array[i] = array[j];
  22.                 array[j] = temp;
  23.             }
  24.         }
  25.     }
  26.     // printing first 4 numbers
  27.     for (i = 0; i < 4; i++) {
  28.         printf("%d ", array[i]);
  29.     }
  30.     getch();
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement