-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04nov_1.c
125 lines (111 loc) · 4.01 KB
/
04nov_1.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <stdio.h>
#include <string.h>
struct Patient {
char name[50];
int age;
char bloodGroup[5];
};
int main() {
struct Patient patients[100]; // Array to hold patient details
int n, i;
// Input the number of patients
printf("Enter the number of patients (max 100): ");
scanf("%d", &n);
// Input details for each patient
for (i = 0; i < n; i++) {
printf("Enter details for patient %d:\n", i + 1);
printf("Name: ");
scanf("%s", patients[i].name);
printf("Age: ");
scanf("%d", &patients[i].age);
printf("Blood Group: ");
scanf("%s", patients[i].bloodGroup);
}
// To find the patient with the maximum age for each blood group
struct Patient oldestPatient;
int found;
printf("\nPatient(s) with the highest age in each blood group:\n");
for (i = 0; i < n; i++) {
found = 0;
// Check if this blood group has already been processed
for (int j = 0; j < i; j++) {
if (strcmp(patients[i].bloodGroup, patients[j].bloodGroup) == 0) {
found = 1;
break;
}
}
// If it's a new blood group, find the oldest patient
if (!found) {
oldestPatient = patients[i]; // Initialize with the current patient
for (int k = i + 1; k < n; k++) {
if (strcmp(patients[k].bloodGroup, oldestPatient.bloodGroup) == 0) {
if (patients[k].age > oldestPatient.age) {
oldestPatient = patients[k]; // Update if older
}
}
}
// Print the oldest patient for this blood group
printf("Blood Group: %s, Name: %s, Age: %d\n",
oldestPatient.bloodGroup,
oldestPatient.name,
oldestPatient.age);
}
}
return 0;
}
//---------------------------------------------------------------------------------------
// #include <stdio.h>
// #include <string.h>
// struct Patient {
// char name[50];
// int age;
// char bloodGroup[5];
// };
// int main() {
// struct Patient patients[100]; // Array to hold patient details
// int n, i;
// // Input the number of patients
// printf("Enter the number of patients (max 100): ");
// scanf("%d", &n);
// // Input details for each patient
// for (i = 0; i < n; i++) {
// printf("Enter details for patient %d:\n", i + 1);
// printf("Name: ");
// scanf("%s", patients[i].name);
// printf("Age: ");
// scanf("%d", &patients[i].age);
// printf("Blood Group: ");
// scanf("%s", patients[i].bloodGroup);
// }
// // To find the patient with the maximum age for each blood group
// struct Patient oldestPatient;
// int found;
// printf("\nPatient(s) with the highest age in each blood group:\n");
// for (i = 0; i < n; i++) {
// found = 0;
// // Check if this blood group has already been processed
// for (int j = 0; j < i; j++) {
// if (strcmp(patients[i].bloodGroup, patients[j].bloodGroup) == 0) {
// found = 1;
// break;
// }
// }
// // If it's a new blood group, find the oldest patient
// if (!found) {
// oldestPatient = patients[i]; // Initialize with the current patient
// for (int k = i + 1; k < n; k++) {
// if (strcmp(patients[k].bloodGroup, oldestPatient.bloodGroup) == 0) {
// if (patients[k].age > oldestPatient.age) {
// oldestPatient = patients[k]; // Update if older
// }
// }
// }
// // Print the oldest patient for this blood group
// printf("Blood Group: %s, Name: %s, Age: %d\n",
// oldestPatient.bloodGroup,
// oldestPatient.name,
// oldestPatient.age);
// }
// }
// return 0;
// }