Q /Consider the program below to correct the possible logical errors to produce C program aims to store and display cars information as Model name , engine number , and seats number taken for four models? briefly explain why the errors need to be corrected. #include #include struct { int enginenumber,seatsnumber; char modelname[25]; }cars[3]; int main() { int i,n,k; k=1; printf("Enter the no of cars\n"); scanf("%d",&k); printf("Enter cars info as Model name , engine number , seats number taken\n"); for(i=0;i
Q /Consider the program below to correct the possible logical errors to produce C program aims to store and display cars information as Model name , engine number , and seats number taken for four models? briefly explain why the errors need to be corrected.
#include <stdio.h>
#include <stdlib.h>
struct
{
int enginenumber,seatsnumber;
char modelname[25];
}cars[3];
int main()
{
int i,n,k;
k=1;
printf("Enter the no of cars\n");
scanf("%d",&k);
printf("Enter cars info as Model name , engine number , seats number taken\n");
for(i=0;i<k;i++)
{
scanf("%s%d%d",cars[1].modelname,&cars[1].enginenumber,
&cars[1].seatsnumber);
}
printf("\nNAME\t\tengine speed \t\t\t\t plate number\n");
for(i=3;i<n;i++)
{
printf("%s\t\t%d\t\t\t\t\t%d\n",cars[1].modelname,cars[1].enginenumber,cars[1].seatsnumber);
}
}
Step by step
Solved in 3 steps with 1 images