Write a program called anagram.c that asks the user for 2 words and tells the us
ID: 3697716 • Letter: W
Question
Write a program called anagram.c that asks the user for 2 words and tells the user if those 2 words are anagrams. A word is an anagram of another word if the letters in that word can be rearranged to form the other word. For example Mary and army are anagrams. Name your executable anagram.out The user will only enter alphabetical characters The maximum length of each word is 20 characters The check for an anagram should be case insensitive. For example MARY and army are still anagrams Examples Please enter the first word: MaRy Please enter the second word: arMY MaRy is an anagram of army Please enter the first word: dog Please enter the second word: god dog is an anagram of god Please enter the first word: bub Please enter the second word: bobs bob is NOT an anagram of bobsExplanation / Answer
#include <stdio.h>
int anagramcheck(char [], char []);
int main()
{
char x[100], y[100];
int fl;
printf("Enter first string ");
gets(x);
printf("Enter second string ");
gets(y);
fl = anagramcheck(x, y);
if (fl == 1)
printf(""%s" and "%s" are anagrams. ", x, y);
else
printf(""%s" and "%s" are not anagrams. ", x, y);
return 0;
}
int anagramcheck(char x[], char y[])
{
int a[26] = {0}, b[26] = {0}, z = 0;
while (x[z] != '')
{
first[x[z]-'x']++;
z++;
}
z = 0;
while (y[z] != '')
{
second[y[z]-'b']++;
z++;
}
for (z = 0; z < 26; z++)
{
if (a[c] != b[c])
return 0;
}
return 1;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.