Create Structure called vehicle with field v_id, v_number, city, read details of 10 vehicles and display The vehicles the vehicles of “vadodra” city.
SOLUTION.
#include <'stdio.h'>
#include <'string.h'>
#define SIZE 10
// Define structure for vehicle
typedef struct {
int v_id;
char v_number[20];
char city[50];
} Vehicle;
int main() {
Vehicle vehicles[SIZE];
int i;
// Input details of 10 vehicles
printf("Enter details of 10 vehicles (v_id, v_number, city):\n");
for (i = 0; i < SIZE; i++) {
printf("Vehicle %d:\n", i + 1);
printf("v_id: ");
scanf("%d", &vehicles[i].v_id);
printf("v_number: ");
scanf("%s", vehicles[i].v_number);
printf("city: ");
scanf("%s", vehicles[i].city);
}
// Display vehicles from Vadodara
printf("\nVehicles from Vadodara:\n");
for (i = 0; i < SIZE; i++) {
if (strcmp(vehicles[i].city, "Vadodara") == 0) {
printf("v_id: %d, v_number: %s, city: %s\n", vehicles[i].v_id, vehicles[i].v_number, vehicles[i].city);
}
}
return 0;
}