-
Notifications
You must be signed in to change notification settings - Fork 1
/
struct_car.c
53 lines (37 loc) · 1.08 KB
/
struct_car.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
#include<stdio.h>
#include<stdlib.h>
struct Car{
char company_name[20],model[30],type[10];
float mileage,horsepower;
};
int main(){
int length,i;
//Enter No. of Elements
printf("Enter No. of Cars \n");
scanf("%d",&length);
//Struct Car Array
struct Car car[20];
for(i=0;i<length;i++){
//Company Name
printf("\nEnter Car Name :\n");
scanf(" %[^\n]s ",car[i].company_name);
//Model
printf("Enter %s \'s Model :\n",car[i].company_name);
scanf(" %[^\n]s ",car[i].model);
//Type
printf("Enter %s \'s Type :\n",car[i].company_name);
scanf(" %[^\n]s",car[i].type);
//Mileage
printf("Enter %s \'s Mileage:\n",car[i].company_name);
scanf("%f",&car[i].mileage);
//Horsepower
printf("Enter %s \'s Horsepower:\n",car[i].company_name);
scanf("%f",&car[i].horsepower);
printf("\nRecorded !!! \n");
}
printf("\nDetails\n");
for(i=0;i<length;i++){
printf("%s\t%s\t%s\t%f\t%f\n",car[i].company_name,car[i].model,car[i].type,car[i].mileage,car[i].horsepower);
}
return 0;
}