Home
»
» Unlabelled
» C++ Program Compare Two Strings Are Equal Or Not
Write program to compare two strings they are exact equal or not.
Source Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| #include<iostream>
using namespace std;
int main( )
{
char str1[80], str2[80];
cout<<"Enter first string: ";
gets(str1);
cout<<"Enter second string: ";
gets(str2);
int i;
for (i = 0; str1[i] == str2[i] && str1[i]!= '\0' && str2[i] != '\0'; i++);
if(str1[i] - str2[i] == 0)
cout << "Strings are equal";
else
cout << "Strings are not equal";
return 0;
}
|
Enter first string: Mango
Enter second string: Man
Strings are not equal
Enter first string: Mango
Enter second string: Mango
Strings are equal
Post a Comment