forked from TheAlgorithms/C
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quartile.c
47 lines (44 loc) · 944 Bytes
/
quartile.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a[10], n, i, j, temp;
float q1, q3, iqr;
printf("Enter no. for Random Numbers :");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
a[i] = rand() % 100;
}
printf("Random Numbers Generated are :\n");
for (i = 0; i < n; i++)
{
printf("\n%d", a[i]);
}
printf("\n");
printf("\nSorted Data:");
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
if (a[i] < a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
for (i = 0; i < n; i++)
{
printf("\n%d", a[i]);
}
q1 = a[n / 4];
printf("\nFirst Quartile : %f", q1);
q3 = a[(3 * n) / 4];
printf("\nThird Quartile : %f", q3);
iqr = q3 - q1;
printf("\nInterQuartile Range is : %f", iqr);
return 0;
}