1.

Write a program to read 2 strings and compare it.

Answer»

# include<iostream> 

# include<cstdio> 

# include<cstring> 

using namespace std; 

int main()

{

int m;

char str1[100],str2[100];

cout<<"Enter first string";

gets(str1);

cout<<"Enter second string";

gets(str2);

m=strcmp(str1,str2);

if(m<0)

cout<<str1<<"is less than"<<str2;

else if(m>0)

cout<<str1<<"is greater than"<<str2;

else

cout<<str1<<"is equal to"<<str2;

}



Discussion

No Comment Found