Anagram in C

Here is the program for anagram in c.

 

Two strings are said to be anagrams if by rearranging the characters of any one string will make both strings equal.

 

Example:
“adssfa” and “dsasfa” are anagrams
“adsfa” and “sdfac” are not anagrams

How to Check two Strings are Anagrams or not?

So what we will do is find the frequency of each characters in first and second string and store it in two arrays. Now we will check the frequency of each character in two strings by comparing the two arrays. If every character has same frequency then the strings are anagrams otherwise not. Below I have written a C program to implement this logic. If you are finding any difficulty then comment below, I will try to solve your problem.

 

Anagram Program in C

 

Output:

C Program to Check two Strings are Anagrams or not, Anagram Program in C

One thought on “Anagram in C

  1. Ekta

    Can you please explain me what is the meaning of using s[str[i]-97]=count; and
    for(i=0;i<26;++i)
    {
    if(s1[i]!=s2[i])
    {
    flag=0;
    break;
    }
    }
    in above program…………

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *