Write a program that finds the \"smallest\" and \"largest\" in a series of words
ID: 1798280 • Letter: W
Question
Write a program 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.Explanation / Answer
#include #include #include #define size 20 int main() { char largest_word[size]; char smalest_word[size]; char wrd[size]; int ch; printf("Enter a word: "); scanf("%s", wrd); strcpy(largest_word, wrd); strcpy(smalest_word, wrd); while(strlen(wrd) != 4 ) { printf("Enter a word: "); scanf("%s", wrd); if( strcmp(smalest_word, wrd) > 0 ) strcpy(smalest_word, wrd); if( strcmp(largest_word, wrd) < 0 ) strcpy(largest_word, wrd); } printf("The Smalest word: %s ", smalest_word); printf("The Largest word: %s ", largest_word); return 0; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.