-
Notifications
You must be signed in to change notification settings - Fork 1
/
teststruct.c
43 lines (34 loc) · 959 Bytes
/
teststruct.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
#include <stdio.h>
struct Distance
{
int feet;
float inch;
} dist1, dist2, sum;
int main()
{
printf("1st distance\n");
// Input of feet for structure variable dist1
printf("Enter feet: ");
scanf("%d", &dist1.feet);
// Input of inch for structure variable dist1
printf("Enter inch: ");
scanf("%f", &dist1.inch);
printf("2nd distance\n");
// Input of feet for structure variable dist2
printf("Enter feet: ");
scanf("%d", &dist2.feet);
// Input of feet for structure variable dist2
printf("Enter inch: ");
scanf("%f", &dist2.inch);
sum.feet = dist1.feet + dist2.feet;
sum.inch = dist1.inch + dist2.inch;
if (sum.inch > 12)
{
//If inch is greater than 12, changing it to feet.
++sum.feet;
sum.inch = sum.inch - 12;
}
// printing sum of distance dist1 and dist2
printf("Sum of distances = %d\'-%.1f\"", sum.feet, sum.inch);
return 0;
}