Advertisement
Guest User

Untitled

a guest
May 24th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.10 KB | None | 0 0
  1. typedef struct
  2. {
  3.     char car_name[25];
  4.     char color[20];
  5.     float km;
  6. }car;
  7.  
  8. void get_data(car [], int);
  9. void print_all(car [], int);
  10. void main(void)
  11. {
  12.     int num;
  13.     car arr[N];
  14.     printf("How many cars are in your shop?\n");
  15.     while(scanf("%d",&num)!=1||num<=0||num>30)
  16.     {
  17.         printf("Error. The num must be between 1-30!\n");
  18.         fflush(stdin);
  19.     }
  20.     get_data(arr, num);
  21.     print_all(arr, num);
  22. }
  23.  
  24. void get_data(car arr[],int num)
  25. {
  26.     int i;
  27.     float x;
  28.     for(i=0;i<num;i++)
  29.     {
  30.         fflush(stdin);
  31.         printf("Enter mark of %d car:\n",i+1);
  32.         gets(arr[i].car_name);
  33.         printf("Enter color of %d car:\n",i+1);
  34.         fflush(stdin);
  35.         gets(arr[i].color);
  36.         printf("Enter km of %d car:\n",i+1);
  37.         scanf("%f",&x);
  38.         arr[i].km=x;
  39.     }
  40. }
  41.  
  42. void print_all(car arr[], int num)
  43. {
  44.     int i;
  45.     for(i=0;i<num;i++)
  46.     {
  47.         printf("Mark of %d car is: %s\n",i+1,arr[i].car_name);
  48.         printf("Color of %d car is: %s\n",i+1,arr[i].color);
  49.         printf("Km of %d car is: %.2f\n",i+1,arr[i].km);
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement