-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathAnagram.c
More file actions
41 lines (34 loc) · 691 Bytes
/
Anagram.c
File metadata and controls
41 lines (34 loc) · 691 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// C code to check if the given two strings are anagram or not.
// Author: sakshisingh02
#include <stdio.h>
void checkanagram(char str1[], char str2[])
{
int arr[26] = {0};
int i;
for (i = 0; (str1[i] != '\0' && str2[i] != '\0'); i++)
{
arr[str1[i] - 'a']++;
arr[str2[i] - 'a']--;
}
if (str1[i] || str2[i])
{
printf("Not anagram!");
return;
}
for (i = 0; i < 26; i++)
{
if (arr[i] != 0)
{
printf("Not anagram!");
return;
}
}
printf("Anagram!");
}
int main()
{
char str1[] = "abc";
char str2[] = "bca";
checkanagram(str1, str2);
return 0;
}