struct Passenger {char name[50];int num_items;int total_weight;};
int main() {int N;printf("Enter the number of passengers: ");scanf("%d", &N);
}
struct Passenger {
char name[50];
int num_items;
int total_weight;
};
int main() {
struct Passenger passengers[N];int N;
printf("Enter the number of passengers: ");
scanf("%d", &N);
// Input passenger information
FILE *fp = fopen("passengers.txt", "w");
if (fp == NULL) {
printf("Error opening file\n");
return 1;
}
for (int i = 0; i < N; i++) {
printf("Enter passenger %d name: ", i + 1);
scanf("%s", passengers[i].name);
printf("Enter number of items for passenger %d: ", i + 1);
scanf("%d", &passengers[i].num_items);
printf("Enter total weight of items for passenger %d: ", i + 1);
scanf("%d", &passengers[i].total_weight);
fprintf(fp, "%s %d %d\n", passengers[i].name, passengers[i].num_items, passengers[i].total_weight);
}
fclose(fp);
// Find passenger with smallest baggage
fp = fopen("passengers.txt", "r");
if (fp == NULL) {
printf("Error opening file\n");
return 1;
}
struct Passenger smallest_baggage;
smallest_baggage.num_items = passengers[0].num_items;
smallest_baggage.total_weight = passengers[0].total_weight;
for (int i = 0; i < N; i++) {
fscanf(fp, "%s %d %d", passengers[i].name, &passengers[i].num_items, &passengers[i].total_weight);
if (passengers[i].num_items < smallest_baggage.num_items || (passengers[i].num_items == smallest_baggage.num_items && passengers[i].total_weight < smallest_baggage.total_weight)) {
smallest_baggage = passengers[i];
}
}
printf("Passenger with the smallest baggage:\n");
printf("Name: %s\nNumber of items: %d\nTotal weight: %d\n", smallest_baggage.name, smallest_baggage.num_items, smallest_baggage.total_weight);
fclose(fp);
return 0;
}