Write a program that tests whether two words are anagrams, thatis, permutations
ID: 3614117 • Letter: W
Question
Write a program that tests whether two words are anagrams, thatis, permutations of the same letters:
Enter the first word: smartest
Enter the second word: mattress
The words areanagrams
Enter the first word: dumbest
Enter the second word: stumble
The words are notanagrams
Write a loop that reads the first word, character by character,using an array of 26 integers to keep track of how many of eachletter has been sent. For example, after the word smartest hasbeen entered, the array should contain the values
1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 2 2 0 0 0 0 0 0, reflecting thefact that smartest contains one a, one e, onem, one r, two s’s and twot’s. Use another loop to read in the secondword, except this time decrementing the corresponding array elementas each letter is read. Both loops should ignore anycharacters that aren’t letters, and both should treatupper-case letters as being the same as their lower-caseversion. After the second word has been processed, use a thirdloop to check if all the entries in the array are zero. If so,the two words are anagrams, otherwise not. Hint: you willprobably wish to use functions from <ctypes.h> , such asisalpha and tolower.
Explanation / Answer
please rate - thanks #include #include #include int main() { char an1[30],an2[30]; int check[26]={0},i; printf("Enter 1st phrase: "); scanf("%s",&an1); printf("Enter 2nd phrase: "); scanf("%s",&an2); for(i=0;iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.