1 . Write a C Program ( NOT C++) Using Video Studios 2015 that finds the \"small
ID: 3775874 • Letter: 1
Question
1. Write a C Program ( NOT C++) Using Video Studios 2015 that finds the "smallest" and "largest" in a series of words. After the user enters the words, the program will determine which words would come first and last if the words were listed in dictionary order. The program must stop accepting input when the user enters a four letter word. Assume that no word is more than 20 letters long.
2.Write a c Program (NOT C++) Using Visual Studios 2015 that Defines the structure “HoursMinutesSeconds” with three simple variables int Hours, int Minutes and float Seconds to declare times in Hours, Minutes and Seconds. Then write a program to add two HoursMinutesSeconds times and store the result in the third HoursMinutesSeconds time. Remember to make necessary seconds to Minutes and Minutes to hour conversions. Note: 60 Seconds = 1 minute and 60 Minutes = 1 hour.
OUTPUT 1 hours 25 minutes 30 seconds
+ 2 hours 35 minutes 20 seconds
-----------------------------------------
4 hours 0 minutes 50 seconds
3. write a C program(NOT C++) Using Visual Studios 2015 that asks the user to enter an international dialing code and then looks it up in the Country_codes array, If it finds the code, the program should display the name of the corresponding country; if not the program should print an error message.
Explanation / Answer
Answer 2:
#include <stdio.h>
struct HoursMinutesSeconds
{
int Hours,Minutes;
float Seconds;
};
int main(void)
{
struct HoursMinutesSeconds time1;
printf(" --------Time 1--------");
printf(" Enter Hours : ");
scanf("%d",&time1.Hours);
printf(" Enter Minutes : ");
scanf("%d",&time1.Minutes);
printf(" Enter Seconds : ");
scanf("%f",&time1.Seconds);
struct HoursMinutesSeconds time2;
printf(" --------Time 2--------");
printf(" Enter Hours : ");
scanf("%d",&time2.Hours);
printf(" Enter Minutes : ");
scanf("%d",&time2.Minutes);
printf(" Enter Seconds : ");
scanf("%f",&time2.Seconds);
struct HoursMinutesSeconds time3;
time3.Hours=time1.Hours+time2.Hours;
time3.Minutes=time1.Minutes+time2.Minutes;
if(time3.Minutes>=60)
{
time3.Minutes=time3.Minutes%60;
time3.Hours+=1;
}
time3.Seconds=time1.Seconds+time2.Seconds;
if(time3.Seconds>=60)
{
time3.Seconds=(int)time3.Seconds%60;
time3.Minutes+=1;
}
printf(" --------Time 3--------");
printf(" Hours : %d",time3.Hours);
printf(" Minutes : %d",time3.Minutes);
printf(" Seconds : %.0f",time3.Seconds);
return 0;
}
Answer 3:
#include <stdio.h>
int main(void)
{
int i,code,status=1;
int Country_codes[9]={10,20,30,40,50,60,70,80,90};
char country[][20]={"India","America","Russia","Pakistan","Nepal","Japan","Mexico","Shri Lanka","Bangladesh"};
printf(" Enter an international dialing code : ");
scanf("%d",&code);
for(i=0;i<sizeof(Country_codes)/sizeof(int);i++)
{
if(code==Country_codes[i])
{
printf(" Country : %s",country[i]);
status=1;
break;
}
else
status=0;
}
if(status==0)
printf(" Country not Found!!!");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.