forked from CO18301/HackotberFest2021
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstring_equal.cpp
54 lines (27 loc) · 857 Bytes
/
string_equal.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include<string> //for using string data type
#include<cstdio> //for using getline function to input string
using namespace std;
int main()
{ string s1,s2;
cout<<"Enter First string\n"; //inputting string1
getline(cin,s1);
cout<<"Enter Second string\n"; //inputting string 2
getline(cin,s2);
if(s1.length()!=s2.length()) //comparing the string length
cout<<"The given strings are unequal";
else
{ int ctr=0; //comparing each character of the two strings
for(int i=0;i<s1.length();++i)
{ if(s1[i]!=s2[i])
{ ctr=1;
break;
}
}
if(ctr==0) //printing the result
cout<<"The given Strings are equal\n";
else
cout<<"The given strings are unequal";
}
return 0;
}