Asked by
AL MaMun (4 Golds)
Friday, 31 Jul 2020, 04:05 PM
at (Education
Tutorials)
|
|
|
|
A C program to Check Anagrams. #include<stdio.h> int check_anagram(char a[], char b[]) { int first[26]= {0}; int second[26]= {0}; int c=0; while(a[c]!='\0') { first[a[c]-'a']++; c++; } c=0; while(b[c]!='\0') { second[b[c]-'a']++; c++; } for(c=0; c<26; c++) { if(first[c]!=second[c]) return 0; } return 1; } int main() { char a[100], b[100]; int flag; gets(a); gets(b); flag=check_anagram(a,b); if(flag==1) printf("%s and %s are anagrams", a, b); else printf("%s and %s are not anagrams", a, b); return 0; } |