Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- int main()
- {
- //clrscr();
- // array for storing given data
- int array[10];
- // auxiliary variables
- int i, j, temp;
- //taking input
- for (i = 0; i < 5; i++) {
- scanf("%d", &array[i]);
- }
- //sorting in descending order(this sorting algorithm is known as Bubble sort. It is most easiest sorting technique to implement for beginners/novices)
- for (i = 0; i < 5; i++) {
- for (j = i + 1; j < 5; j++) {
- // here "<" sign sorts this array in descending order. if you change it ">", it will sort in ascending order
- if (array[i] < array[j]) {
- // below three lines are for swaping value i.e. a = 2, b = 4 after swaping a = 4, b = 2
- temp = array[i];
- array[i] = array[j];
- array[j] = temp;
- }
- }
- }
- // printing first 4 numbers
- for (i = 0; i < 4; i++) {
- printf("%d ", array[i]);
- }
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement