Write a C++ program to compare two strings entered by the user.

Program Code:
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
char str1[50], str2[50];
cout<<"Enter first string to make a comparison : ";
gets(str1);
cout<<endl;
cout<<"Enter second string to make a comparison :";
gets(str2);
cout<<endl;
if(strcmp(str1, str2) == 0)
{
cout<<"Entered strings are equal.";
}
else
{
cout<<"Entered strings are not equal.";
}
return 0;
}


The program output is tested on www.jdoodle.com
Output:
Enter first string to make a comparison: Mukesh Kumar
Enter second string to make a comparison : Mukesh Rajput
Entered strings are not equal.


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: