-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuser-defined-dtypes.c
More file actions
74 lines (66 loc) · 1.88 KB
/
user-defined-dtypes.c
File metadata and controls
74 lines (66 loc) · 1.88 KB
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
72
73
74
//var25
//lab7
#include <stdio.h>
#include <math.h>
// 1. Enumeration type
enum music{
classic, //0
pop, //1
rock, //2
rap, //...
electronic,
disco
};
// 2. Struct
struct pair{
int x;
int y;
};
struct square{
struct pair ulc; // upper left corner
struct pair llc; // lower left corner
struct pair urc; // upper right corner
struct pair lrc; // lower right corner
float side;
float P;
};
//3. Union
struct x_bit{
unsigned int ready : 1; // 0 - 1
unsigned int toner : 1; // 0 - 1
unsigned int drum : 1; // 0 - 1
unsigned int paper : 1; // 0 - 1
};
union printer{
struct x_bit x_b;
int x;
};
int main() {
//------------------------------------
int s = rock;
printf("Number of the rock is: %d", s);
printf("\n");
//------------------------------------
struct square my_sqr;
printf("Enter ulc coordinates(x, y): ");
scanf("%d%d", &my_sqr.ulc.x, &my_sqr.ulc.y);
printf("Enter llc coordinates(x, y): ");
scanf("%d%d", &my_sqr.llc.x, &my_sqr.llc.y);
printf("Enter urc coordinates(x, y): ");
scanf("%d%d", &my_sqr.urc.x, &my_sqr.urc.y);
printf("Enter lrc coordinates(x, y): ");
scanf("%d%d", &my_sqr.lrc.x, &my_sqr.lrc.y);
// Count length side of my square : sqrt((x2 - x1)^2 + (y2 - y1)^2)
// Assumed that the data entered is correct for the all sides of the square
my_sqr.side = (float)sqrt(pow((my_sqr.ulc.x - my_sqr.llc.x), 2) + pow((my_sqr.ulc.y - my_sqr.llc.y), 2));
my_sqr.P = 4 * my_sqr.side;
// I limited my numbers after the dot to 2
printf("%.2f\n", my_sqr.P);
//------------------------------------
union printer m;
scanf("%x", &m.x);
printf("ready : %d \n", m.x_b.ready);
printf("toner : %d \n", m.x_b.toner);
printf("drum : %d \n", m.x_b.drum);
printf("paper : %d \n", m.x_b.paper);
}