Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- int countArray[26] = {0};
- int i,j,p,len1,len2,arrayposition;
- char word1[1000],word2[1000];
- printf("Enter two words you'd like to check for anagrams:");
- fgets(word1, 1000, stdin);
- fgets(word2, 1000, stdin);
- len1 = strlen(word1);
- len2 = strlen(word2);
- for (i = 0; i < len1; i++)
- {
- arrayposition = word1[i] - 'a';
- countArray[arrayposition]++;
- }
- for (j = 0; j < len2; j++)
- {
- arrayposition = word2[j] - 'a';
- countArray[arrayposition]--;
- }
- for (p = 0; p < 26; p++)
- {
- if (countArray[p] != 0) printf("Words are not anagrams"); return 0;
- }
- printf("The words %s and %s are Anagrams!", word1, word2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement