Wednesday, October 31, 2018

STRING: PROGRAM TO COMPARE BETWEEN TWO STRINGS

#include<stdio.h>
void main()
{
char str[20],str2[20];
int i,c1=0,c2=0,f=1;
printf("Enter the string 1:");
gets(str);
printf("Enter the string 2:");
gets(str2);
for(i=0;str[i]!='\0';i++)
{
c1++;
}
for(i=0;str2[i]!='\0';i++)
{
c2++;
    }
    if(c1>c2)
    {
    printf("string 1 %s is greater",str);
}
else if(c2>c1)
{
printf("string 2 %s is greater",str2);
 }
else
{
for(i=0;str[i]!='\0';i++)
{
if(str[i]!=str2[i])
{
f=0;
break;
}
}
if(f==1)
printf("string is equal");
else
printf("string is not equal");
}
}

No comments:

Post a Comment

Static Member Function

CODE : #include<iostream> using namespace std; class test  {     int code;       static int count;               //static...