# C Programming – HackerRank Solution | ANAGRAM 62 |

### (HackerRank) Write a Modular C Programming code to solve ANAGRAM 62, Given two strings check if they are anagrams of each other or not.

Given two strings check if they are anagrams of each other or not.

Two Strings are called anagrams of each other if they contain the same characters repeated the same number of times.

Ex: LISTEN and SILENT.

For simplicity consider only upper case alphabets as part of the input.

Input Format

First line contains the first string Second line contains the second string

Constraints

Length of string is<=10^5

Output Format

Output YES if the strings are Anagram else output NO.

Sample Input 0

SILENT
LISTEN

Sample Output 0

YES

Explanation 0

Count of each characters in string 1
count(S) = 1, count(I) = 1, count(L) = 1, count(E) = 1, count(N) = 1, count(T) = 1

count of each character in string 2
count(S) = 1, count(I) = 1, count(L) = 1, count(E) = 1, count(N) = 1, count(T) = 1

We see that count each charaters in both strings are same therefore they are anagram of each other.

CODE:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

int main()
{
char str[1000],ana[1000];
int status=1,i,j,count;
scanf("%s",str);
scanf("%s",ana);
if(strlen(str)==strlen(ana))
{
for(i=0;str[i];i++)
{
j=0;
while(str[j])
{
if(str[i]==str[j])
count++;
j++;
}
j=0;
while(ana[j])
{
if(str[i]==ana[j])
count--;
j++;
}
if(count!=0)
{
status=0;
break;
}
}
if(status==1)
printf("YES");
else
printf("NO");
}
else{
printf("NO");
}
}

OUTPUT

Congratulations, you passed the sample test case.

Click the Submit Code button to run your code against all the test cases.

Input (stdin)

SILENT
LISTEN

YES
Expected Output

YES

Please find some more codes of Loops, Condition Statements, 1D Arrays, 2D Arrays, Strings, Pointers, Data Structures, Files, Linked lists, Stacks, Queues, Binary Trees, MISC, Solved model question papers & Hacker Rank all solutions on the below page:

Top 100+ C Programming codes – KLE Technological University