forked from taniadovzhenko/CppPracticum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrect.c
More file actions
73 lines (48 loc) · 939 Bytes
/
rect.c
File metadata and controls
73 lines (48 loc) · 939 Bytes
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
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <stdlib.h>
typedef struct Rect{
unsigned num;
float x;
float y;
} Rect;
int vvod(Rect* r){
printf("input n, x,y :");
scanf("%u",&(r->num));
scanf("%f",&(r->x));
scanf("%f",&(r->y));
return EXIT_SUCCESS;
}
int addRect(char* fname){
unsigned n;
Rect r1;
scanf("%d", &n);
FILE* f = fopen(fname, "wb");
for(unsigned i=0; i<n;++i){
vvod(&r1);
fwrite(&r1,1,sizeof(r1),f);
}
fclose(f);
}
unsigned maxrect(char * fname){
unsigned n;
Rect r1;
FILE* f = fopen(fname, "rb");
double maxarea = 0;
while(!feof(f)){
int r =fread(&r1,sizeof(r1),1,f);
if(r<1) break;
float w = r1.x;
float h = r1.y;
if(w*h>maxarea){
maxarea = w*h;
n = r1.num;
}
}
fclose(f);
printf("Max sqr = %lf", maxarea);
return n;
}
int main(){
addRect("rect.dat");
printf("%u", maxrect("rect.dat"));
}