---
title: "How to check if two String are Anagram?"  
description: "How to check if two String are Anagram?"  
author: "Ronan Jone"  
published: 2018-02-27  
canonical: https://answers.mindstick.com/qa/35072/how-to-check-if-two-string-are-anagram  
category: "programming"  
reading_time: 2 minutes  

---

# How to check if two String are Anagram?

## Answers

### Answer by Arti Mishra

**Anagrams String :** A string is called anagram string if another [string contains](https://www.mindstick.com/forum/159365/how-to-check-if-a-string-contains-letters-only-in-sql) same [characters](https://answers.mindstick.com/qa/42112/who-is-the-originator-of-avengers-characters), only the [order](https://yourviews.mindstick.com/view/70545/unnao-rape-case-law-order-has-gone-paralyzed-sorry-women-it-cannot-save-you) of characters can be different. For example, “abcd” and “dabc” are anagram of each other. To [check whether](https://www.mindstick.com/forum/457/what-is-the-best-way-to-check-whether-a-trigger-exists-in-sql-server) two [Strings are Anagrams](https://www.mindstick.com/forum/157930/write-a-program-to-check-if-two-strings-are-anagrams-of-each-other) String we need to follow these step - Step-1. First be take two strings as input. Step-2. Sort two strings according to their ASCII values. Step-3. Now [compare](https://www.mindstick.com/blog/11580/sahara-mutual-fund-compare-current-mutual-funds-scheme) the two strings. If both are equal, then they are anagrams. Otherwise they are not anagrams.**Example :**\

```
#include <stdio.h>

int find_anagram(char [], char []);

int main()
{
    char array1[100], array2[100];
    int flag;

    printf("Enter the string\n");
    gets(array1);
    printf("Enter another string\n");
    gets(array2);
    flag = find_anagram(array1, array2);
    if (flag == 1)
        printf(""%s" and "%s" are anagrams.\n", array1, array2);
    else
        printf(""%s" and "%s" are not anagrams.\n", array1, array2);
    return 0;
}

int find_anagram(char array1[], char array2[])
{
    int num1[26] = {0}, num2[26] = {0}, i = 0;

    while (array1[i] != '\0')
    {
        num1[array1[i] - 'a']++;
        i++;
    }
    i = 0;
    while (array2[i] != '\0')
    {
        num2[array2[i] -'a']++;
        i++;
    }
    for (i = 0; i < 26; i++)
    {
        if (num1[i] != num2[i])
            return 0;
    }
    return 1;
}
```

\
\
\
\
\
\


---

Original Source: https://answers.mindstick.com/qa/35072/how-to-check-if-two-string-are-anagram

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
