Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions C/program-54/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A program in C which checks whether two strings are anagrams or not

An anagram of a string is another string that contains same characters, only the order of characters can be different.
31 changes: 31 additions & 0 deletions C/program-54/program.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include<stdio.h>
int main()
{
char a[100],b[100];
int f[26]={0};
int s[26]={0};
int k;
int len1,len2;
printf("Enter the two strings\n");
fgets(a,100,stdin);
fgets(b,100,stdin);
for(int i=0;a[i]!='\0';++i)
f[a[i]-'a']+=1;
for(int i=0;b[i]!='\0';++i)
s[b[i]-'a']+=1;
len1 = sizeof(a)/sizeof(a[0]);
len2 = sizeof(b)/sizeof(b[0]);
if(len1 == len2)
{
for(k=0;k<26;++k)
if(f[k]!=s[k])
break;
if(k==26)
printf("The strings are anagrams.\n");
else
printf("The strings aren't anagrams.");
}
else
printf("The strings aren't anagrams.");
return 0;
}