Saturday, August 18, 2018

STRING COMPARE


  • Problem Description

    Write a program to read to strings and compare them using the function strcmp() and
    print a message that the first string is equal, less or greater than the second one.

    Example

    Input:
    SRM
    SRMUniversity

    Output:
    First String is Less Than Second String

    Input:
    SRMUNIVERSITY
    SRMLC

    Output:
    First String is Greater Than Second String
  • CODING ARENA
  • #include <stdio.h>
    #include<string.h>
    int main()
    {
      char str1[50],str2[50];
      scanf("%s%s",str1,str2);
      if(strcmp(str1,str2)>0)
      {
        printf("First String is Greater Than Second String");
      }
      if(strcmp(str1,str2)<0)
      {
        printf("First String is Less Than Second String");
      }
      if(strcmp(str1,str2)==0)
      {
        printf("Both Strings are Equal");
      }
      return 0;
    }
  • Test Case 1

    Input (stdin)
    SRMUniversity
    
    SRM
    
    
    Expected Output
    First String is Greater Than Second String
  • Test Case 2

    Input (stdin)
    SRM
    
    SRM
    
    
    Expected Output
    Both Strings are Equal

No comments:

Post a Comment