WEEK 5
WEEK 5
Problem Statement:
Write a Program, which generate 100 real numbers in the range of 10.0 to 20.0,
and sort them in descending order.
Aim:
Write a C Program which generate 100 real numbers and sort them in
descending order.
Software Requirements:
Description:
In this program, we need to sort the given array in descending order such that
elements will be arranged from largest to smallest. This can be achieved
through two loops. Outer loop will select an element and inner loop allow us to
compare selected element with rest of the elements.
Original array:
Elements will be sort in such a way that largest element will appear on extreme
left which in this case is 8. Smallest element will appear on extreme right which
in this case is 1.
Algorithm:
Step 1: Start
Step 4: Iterate for loop to take array elements as input, and print them.
Step 5: The array elements are in unsorted fashion, to sort them, make a nested
loop.
Step 6: In the nested loop, the each element will be compared to all the
elements below it.
Step 7: In case the element is smaller than the element present below it, then
they are interchanged
Step 8: After executing the nested loop, we will obtain an array in descending
order arranged elements.
Step 9: Stop
Flow Chart:
Source Code:
#include <stdio.h>
#include<conio.h>
int main ()
{
int number[30];
int i, j, a, n;
printf("Enter the value of N\n");
scanf("%d", &n);
2
if (number[i] < number[j])
{
a = number[i];
number[i] = number[j];
number[j] = a;
}
}
}
Compiler (F9): Click on F9 to compile the program which helps us to find the
errors so that the file extends to Sort.exe file name.
Run (F10): After compilation of the program click on F10 to run the program
and gives output.
Output:
3
89
70
65
58
56
45
23
10
4
--------------------------------
Process exited after 46.72 seconds with return value 10
Press any key to continue . . .