5. Mr. Ahamed is very much fond of buying new cars. He planned to buy a brand new Toyota use. Write a 'C' program for the following. car for his day to day i). Accept and display any two Toyota car model names. ii). Find and display the smallest among the given car models. iii). Find and display model. the length of the smallest car iv). Accept car plate number and combine with your new car model. Display it.
using c_compiler
Program:
#include <stdio.h>
#include <string.h>
int main()
{
char firstModel[100];
char secondModel[100];
int numberPlate;
printf("Enter car model 1-1: ");
fgets(firstModel, 100, stdin);
printf("\n");
printf("Enter car model 1-2: ");
fgets(secondModel, 100, stdin);
printf("\n");
printf("Enter car plate number: ");
scanf("%d", &numberPlate);
printf("\n");
printf("Toyota Car model 1-1: %s \n", firstModel);
printf("Toyota Car model 1-2: %s \n", secondModel);
int res = strcmp(firstModel, secondModel);
if (res == 1)
{
printf("The smallest car model name is: %s \n", firstModel);
int length = strlen(firstModel);
printf("The length of your new car model: %d \n", (length - 1));
printf("Car Number & Car Model: %d%s", numberPlate, firstModel);
}
else
{
printf("The smallest car model name is: %s \n", secondModel);
int length = strlen(secondModel);
printf("The length of your new car model: %d \n", (length - 1));
printf("Car Number & Car Model: %d%s", numberPlate, secondModel);
}
return 0;
}
Step by step
Solved in 2 steps with 1 images