-
Notifications
You must be signed in to change notification settings - Fork 0
/
20_Teploty.c
58 lines (40 loc) · 991 Bytes
/
20_Teploty.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
48
49
50
51
52
53
54
55
56
57
58
#include "stdio.h"
#pragma warning(disable:4996)
#include <stdlib.h>
int compare(const void* a, const void* b) {
// If a is smaller, positive value will be returned
if(*(float*)a - *(float*)b < 0){
return 1;
} else if(*(float*)a - *(float*)b > 0){
return -1;
} else {
return 0;
}
//return (*(float*)a - *(float*)b);
}
int main(void)
{
float teploty[4];
float prumer=0 ;
printf("zadejte teploty:\n");
int velikost = sizeof(teploty)/sizeof(float);
for (int i = 0; i < velikost ; i++)
{
scanf("%f", &teploty[i]);
}
for (int i = 0; i < velikost ; i++)
{
prumer += teploty[i];
}
prumer = prumer/velikost;
printf("prumer teplot: %.2f\n" ,prumer);
qsort(teploty, velikost, sizeof(float), compare);
printf("Serazene pole: ");
for(int j=0 ; j<velikost; j++){
printf("%.1lf ", teploty[j]);
}
printf("\n");
printf("Minimum je: %.2f\n", teploty[velikost-1]);
printf("Maximum je: %.2f\n", teploty[0]);
return 0;
}