Skip to main content

Featured

Mastering Hollow Square Patterns in C: Stars, Numbers, Alphabets & Binary

πŸ”’ C Program to Print Hollow Continuous Number Square πŸ“„ Source Code: #include <stdio.h> int main() { int num, k = 0; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { if(i == 1 || i == num || j == 1 || j == num) { // k increments sequentially only along the borders printf("%d ", k++); } else { printf(" "); } } printf("\n"); } return 0; } πŸ“‹ Copy Code πŸ’» Expected Output (Input: 5): Enter the number: 5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 πŸ”’ C Program to Print Standard Hollow Binary Row Square πŸ“„ Source Code (Fixed Specifier): #include <stdio.h> int main() { ...

Check If Two Numbers Are Anagrams - C Program

Check If Two Numbers Are Anagrams - C Program

✅ C Program to Check if Two Numbers Are Anagrams

#include <stdio.h>

int countDigits(int n, int count[]) {
    while (n > 0) {
        count[n % 10]++;
        n /= 10;
    }
}

int areAnagrams(int num1, int num2) {
    int count1[10] = {0};
    int count2[10] = {0};

    countDigits(num1, count1);
    countDigits(num2, count2);

    for (int i = 0; i < 10; i++) {
        if (count1[i] != count2[i])
            return 0; // Not anagrams
    }
    return 1; // Anagrams
}

int main() {
    int num1, num2;
    printf("Enter two numbers: ");
    scanf("%d %d", &num1, &num2);

    if (areAnagrams(num1, num2))
        printf("Yes, the numbers are anagrams of each other.\n");
    else
        printf("No, the numbers are not anagrams.\n");

    return 0;
}
  

πŸ“˜ Explanation:

This C program checks if two numbers are anagrams of each other. An anagram means both numbers contain the same digits in any order. Here's how it works:

  • countDigits() function builds a frequency count array for digits 0–9.
  • Two arrays are created: one for each number's digit frequency.
  • If both frequency arrays match, the numbers are anagrams.
  • Otherwise, they are not.

🧾 Sample Output:

Enter two numbers: 121 211
Yes, the numbers are anagrams of each other.

Enter two numbers: 123 456
No, the numbers are not anagrams.
  

πŸ”‘ Keywords:

Anagram numbers in C, number digit match, frequency count in C, C program for number comparison, logic-based C program, digit counter

πŸ“Œ Hashtags:

#CProgramming #AnagramNumbers #InterviewLogic #DigitFrequency #BeginnerC #CodeWithExplanation

πŸ” Search Description:

This C program checks if two numbers are anagrams by comparing the frequency of digits in both. Efficient and beginner-friendly approach for digit-based problems in C.

Comments

Popular Posts

πŸŒ™