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.


“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



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

3 thoughts on “Anagram in C”

  1. Can you please explain me what is the meaning of using s[str[i]-97]=count; and
    in above program…………

  2. can you explain what this does?
    in the code
    how is the frequency stored I am not able to get it.

Leave a Comment

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