Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main()
  5. {
  6.  
  7. int countArray[26] = {0};
  8. int i,j,p,len1,len2,arrayposition;
  9. char word1[1000],word2[1000];
  10. printf("Enter two words you'd like to check for anagrams:");
  11. fgets(word1, 1000, stdin);
  12. fgets(word2, 1000, stdin);
  13.  
  14. len1 = strlen(word1);
  15. len2 = strlen(word2);
  16.  
  17. for (i = 0; i < len1; i++)
  18. {
  19. arrayposition = word1[i] - 'a';
  20. countArray[arrayposition]++;
  21. }
  22.  
  23.  
  24. for (j = 0; j < len2; j++)
  25. {
  26. arrayposition = word2[j] - 'a';
  27. countArray[arrayposition]--;
  28. }
  29.  
  30. for (p = 0; p < 26; p++)
  31. {
  32. if (countArray[p] != 0) printf("Words are not anagrams"); return 0;
  33. }
  34.  
  35. printf("The words %s and %s are Anagrams!", word1, word2);
  36.  
  37. return 0;
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement