forked from hermanwongkm/CS1010
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tray.c
59 lines (44 loc) · 1.56 KB
/
tray.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>
int min_unused_area(int,int,int,int,int);
double min_perimeter(double,double);
int max_slab(int,int,int,int);
int main(void) {
int trayHeight, trayWidth, slabHeight, slabWidth,maxSlab,unusedArea;
double minPeri;
printf("Enter size of tray: ");
scanf("%d %d",&trayHeight, &trayWidth);
printf("Enter size of slab: ");
scanf("%d %d",&slabHeight, &slabWidth);
maxSlab = max_slab(trayHeight,trayWidth,slabHeight,slabWidth);
unusedArea = min_unused_area(trayHeight,trayWidth,slabHeight,slabWidth,maxSlab);
printf("Minimum unused area = %d\n",unusedArea); // incomplete
minPeri = min_perimeter(trayHeight,trayWidth);
printf("Minimum perimeter after folding = %.2lf\n",minPeri); // incomplete
return 0;
}
int max_slab(int trayHeight,int trayWidth, int slabHeight, int slabWidth){
int firstPosition, secondPosition;
firstPosition =(trayHeight/slabHeight) * (trayWidth/slabWidth);
secondPosition =(trayHeight/slabWidth) *(trayWidth/slabHeight);
if(firstPosition > secondPosition)
return firstPosition;
else
return secondPosition;
}
int min_unused_area(int trayHeight,int trayWidth, int slabHeight, int slabWidth, int number){
int slabArea, trayArea, unusedArea;
trayArea = trayHeight * trayWidth;
slabArea = slabHeight * slabWidth;
unusedArea = trayArea - (slabArea*number);
return unusedArea;
}
double min_perimeter(double trayHeight,double trayWidth){
int i;
for(i = 1; i <= 3; i++){
if(trayHeight > trayWidth)
trayHeight = trayHeight/2;
else if(trayHeight < trayWidth)
trayWidth = trayWidth/2;
}
return (trayHeight+trayWidth)*2;
}