Computer Science, asked by ethanjm2005, 3 months ago

Write code to take two words from the user. The program should convert these to lower case, then compare them: printing a positive number if string1 appears after string2 alphabetically, a negative number if string1 appears before string2 alphabetically and zero if the two strings are identical. Make sure your program does not produce any additional numerical output other than this number or it may not be graded correctly.

Hint - while these instructions don't specify a specific number to print, there is a String method which, if used correctly, will produce a number which matches these conditions in all possible cases.

Answers

Answered by BhargabGanguli
0

Answer:I have attached an (.cpp) file  to run in C software and also typed  it in explanation zone. Please check the attachment if any mistake in typing through explanation. It is written in c language and you can run in Turbo c software.

Explanation:

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()    

{

   int i,x;

   char name1[100],name2[100];

    printf("Enter first word: ");

    gets(name1);

    printf("Enter second word");

    for(i=0;i<strlen(name1);i++)

    {

        name1[i]=name1[i]+32;

    }

   for(i=0;i<strlen(name1);i++)

    {

        name2[i]=name2[i]+32;

    }                                                        

    x=strcmp(name1,name2);

if(x==0)  

{

   printf("two words are identical");

   printf("%d",x);

}

if(x>0)

{  

   printf("1st word appears after 2nd word alphabetically");

   printf("%d",x);

}

if(x<0)  

{  

   printf("2nd word appears after 1st word alphabetically");

   printf("%d",x);

}

getch();

}

Attachments:
Similar questions