Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct
- {
- char car_name[25];
- char color[20];
- float km;
- }car;
- void get_data(car [], int);
- void print_all(car [], int);
- void main(void)
- {
- int num;
- car arr[N];
- printf("How many cars are in your shop?\n");
- while(scanf("%d",&num)!=1||num<=0||num>30)
- {
- printf("Error. The num must be between 1-30!\n");
- fflush(stdin);
- }
- get_data(arr, num);
- print_all(arr, num);
- }
- void get_data(car arr[],int num)
- {
- int i;
- float x;
- for(i=0;i<num;i++)
- {
- fflush(stdin);
- printf("Enter mark of %d car:\n",i+1);
- gets(arr[i].car_name);
- printf("Enter color of %d car:\n",i+1);
- fflush(stdin);
- gets(arr[i].color);
- printf("Enter km of %d car:\n",i+1);
- scanf("%f",&x);
- arr[i].km=x;
- }
- }
- void print_all(car arr[], int num)
- {
- int i;
- for(i=0;i<num;i++)
- {
- printf("Mark of %d car is: %s\n",i+1,arr[i].car_name);
- printf("Color of %d car is: %s\n",i+1,arr[i].color);
- printf("Km of %d car is: %.2f\n",i+1,arr[i].km);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement