-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathanagram.c
More file actions
66 lines (55 loc) · 1.24 KB
/
Copy pathanagram.c
File metadata and controls
66 lines (55 loc) · 1.24 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
// function to count the frequency of each character
//
void count_frequency(char inputString[],int s[])
{
int i=0,j,count;
while(inputString[i]!='\0')
{
j = 0;
count = 0;
while(inputString[j] != '\0')
{
if(inputString[i] == inputString[j])
count++;
j++;
}
s[inputString[i]-97] = count;
i++;
}
}
int main()
{
char inputString1[100],inputString2[100];
int i,j,flag = 1;
int tempString[26] = {0}, auxString[26] = {0};
printf("Enter first inputStringing:");
scanf("%s",inputString1);
printf("Enter second inputStringing:");
scanf("%s",inputString2);
// if the length of the two strings are not equal
if (inputStringlen(inputString1) != inputStringlen(inputString2))
if(inputStringlen(inputString1)!=inputStringlen(inputString2)) //if the lengths of two inputStringings are not equal
{
printf("\nStrings are not anagrams");
exit(0);
}
count_frequency(inputString1,tempString);
count_frequency(inputString2,auxString);
//checking frequency of each character
for (i=0 ; i<26 ; ++i)
{
if(tempString[i] != auxString[i])
{
flag = 0;
break;
}
}
if (flag)
printf("\nStrings are anagrams");
else
printf("\nStrings are not anagrams");
return 0;
}