File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -142,3 +142,7 @@ This is a repository containing various C++ Programs to understand the basic con
142
142
143
143
C++ Code for checking whether binary representation of a number is palindrome or not.
144
144
145
+ * [ Check whether two strings are anagrams of each other] ( https://github.com/altruistcoder/Data-Structures/blob/master/check_anagrams.cpp ) :
146
+
147
+ C++ Code for checking whether two given strings are anagrams of each other.
148
+
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < string.h>
3
+ using namespace std ;
4
+
5
+ bool checkAnagrams (char st1[], char st2[])
6
+ {
7
+ int i, l1 = strlen (st1), res=0 ;
8
+ if (l1 != strlen (st2))
9
+ return false ;
10
+ for (i=0 ; i<l1; i++)
11
+ {
12
+ res = res ^ (int )st1[i];
13
+ res = res ^ (int )st2[i];
14
+ }
15
+ return res==0 ;
16
+ }
17
+
18
+ int main ()
19
+ {
20
+ char s1[100 ], s2[100 ];
21
+ cout<<" Enter the two strings to be checked for being anagrams: " ;
22
+ cin>>s1>>s2;
23
+ if (checkAnagrams (s1, s2))
24
+ cout<<" The given two strings are anagrams of each other\n " ;
25
+ else
26
+ cout<<" The given two strings are not anagrams of each other\n " ;
27
+ return 0 ;
28
+ }
You can’t perform that action at this time.
0 commit comments