#include<string.h>
#include<iostream>
using namespace std;
// Program to compare a string
main()
{
char str1[100], str2[100];
cout<<"Enter a String ";
cin.getline(str1,100);
cout<<str1;
cout<<"Enter a String ";
cin.getline(str2,100);
cout<<str2;
if(strcmp(str1,str2)==0)
cout<<"strings are equal";
else
if(strcmp(str1,str2)>0)
cout<<"\n "<<str1 <<" is greater than " <<str2;
else
if(strcmp(str1,str2)<0)
cout<<"\n "<<str1 <<" is smaller than " <<str2 ;
}
#include<iostream>
using namespace std;
// Program to compare a string
main()
{
char str1[100], str2[100];
cout<<"Enter a String ";
cin.getline(str1,100);
cout<<str1;
cout<<"Enter a String ";
cin.getline(str2,100);
cout<<str2;
if(strcmp(str1,str2)==0)
cout<<"strings are equal";
else
if(strcmp(str1,str2)>0)
cout<<"\n "<<str1 <<" is greater than " <<str2;
else
if(strcmp(str1,str2)<0)
cout<<"\n "<<str1 <<" is smaller than " <<str2 ;
}
No comments:
Post a Comment