two strings is given through the keyboard and fid which one is greater , smaller, or equal and also find their difference 2nd method. ( string )

 






#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
    char str1[20],str2[20];
    int i=0,flag=0, x=0;

    printf("enter the first string :");
    gets(str1);

    printf("enter the second string :");
    gets(str2);

    while (str1[i] != '\0' && str2[i] != '\0')
    {
        x = str1[i]-str2[i];
        if(str1[i] != str2[i])
       { 
           flag=1;
           break;
       }
    
     
       else
       i++;
       
    }

    if (flag==0 && str1[i]=='\0' && str2[i]=='\0')
    printf("\n two string are equal and their difference is %d ",x);

    else 
    printf("\n two strings are not aqual and their difference is %d",x);

}   

output :

enter the first string :R enter the second string :r two strings are not aqual and their difference is -32

Comments

Popular Post

Write the definition for a class called complex that has floating point data members for storing real and imaginary parts. The class has the following member functions: void set(float, float) to set the specified value in object void disp() to display complex number object complex sum(complex) to sum two complex numbers & return complex number 1. Write the definitions for each of the above member functions. 2. Write main function to create three complex number objects. Set the value in two objects and call sum() to calculate sum and assign it in third object. Display all complex numbers.