# Posted By

kausthub13 on 07/19/17

# Statistics

Viewed 3875 times
Favorited by 0 user(s)

# Q.WAP to find the smallest and largest word that a user entered in C language. The program needs to terminate when the user ente

/ Published in: C
`#include<stdio.h>#include<string.h> int count = 0;  // To count the number of wordschar smallest_word[20]; //To store the smallest wordchar largest_word[20]; // To store the largest wordvoid print_words(char phrase[10][20]);// to print all the wordsvoid get_words(char phrase[10][20]);//to get the words from the uservoid compare_words(char phrase[10][20]);//function to find the smallest and the largest word in the group. int main(){    char phrase[10][20];    printf("Enter Words (Enter A 4 letter Word to terminate) \n");    get_words(phrase);    compare_words(phrase);    printf("All the Words Entered Are :\n");    print_words(phrase);    printf("The Largest And Smallest Words Are : \n%s \n%s",largest_word,smallest_word);    return 0 ;} void print_words(char phrase[10][20]){    for(int i = 0 ;i<count;i++)    {        printf("%s\n",phrase[i]);    }} void get_words(char phrase[10][20]){   int length_str = 0;    for(int i = 0 ;length_str!=4;i++)    {        scanf("%s",&phrase[i]);        length_str = strlen(phrase[i]);        ++count;    }} void compare_words(char phrase[10][20]){    strcpy(smallest_word,phrase[0]);    strcpy(largest_word,phrase[0]);    for(int i = 1;i<count;i++)    {        if(strcmp(smallest_word,phrase[i])>0)        {            strcpy(smallest_word,phrase[i]);        }        else if(strcmp(largest_word,phrase[i])<0)        {            strcpy(largest_word,phrase[i]);        }    }}`