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

Define a class to represent a Bank Account. Include the following members: Data Members: i. Name of the depositor ii. Account number iii. Type of account iv. Balance amount in the account Member Functions: 1. To Input initial values 2. To deposit an amount 3. To withdraw an amount after checking the balance 4. To display name and balance Also write constructor for this class that takes four arguments. It should also handle type of account as savings by default