Preview:
#include <stdio.h>
#include <string.h>

int main() {
    char word1[100], word2[100];
    int freq1[26] = {0}, freq2[26] = {0};

    // Prompt user to enter the first word
    printf("Word 1: \n");
    scanf("%s", word1);

    // Prompt user to enter the second word
    printf("Word 2: \n\n");
    scanf("%s", word2);

    // Count frequency of each letter in word1
    for (int i = 0; i < strlen(word1); i++) {
        if ((word1[i] >= 'a' && word1[i] <= 'z') || (word1[i] >= 'A' && word1[i] <= 'Z')) {
            if (word1[i] >= 'A' && word1[i] <= 'Z') {
                freq1[word1[i] - 'A']++;
            } else {
                freq1[word1[i] - 'a']++;
            }
        }
    }

    // Count frequency of each letter in word2
    for (int i = 0; i < strlen(word2); i++) {
        if ((word2[i] >= 'a' && word2[i] <= 'z') || (word2[i] >= 'A' && word2[i] <= 'Z')) {
            if (word2[i] >= 'A' && word2[i] <= 'Z') {
                freq2[word2[i] - 'A']++;
            } else {
                freq2[word2[i] - 'a']++;
            }
        }
    }

    // Compare the frequency arrays
    int match = 1;
    for (int i = 0; i < 26; i++) {
        if (freq1[i] != freq2[i]) {
            match = 0;
            break;
        }
    }

    // Print the result
    if (match) {
        printf("YES! %s and %s\n", word1, word2);
    } else {
        printf("NO!\n");
    }

    return 0;
}

downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter