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() { ...

C Program to Check Armstrong Number (Any Digits)

C Program to Check Armstrong Number (Any Digits)

✅ C Program to Check Armstrong Number (Any Digits)

#include <stdio.h>

int main()
{
    int num, temp, remainder, sum = 0, n = 0;

    printf("Enter the number:\n");
    scanf("%d", &num);

    temp = num;

    // count digits
    int digits = num;
    while(digits != 0) {
        digits /= 10;
        n++;
    }

    temp = num;
    while(num > 0) {
        remainder = num % 10;

        // calculate remainder^n manually
        int power = 1;
        for(int i = 0; i < n; i++) {
            power *= remainder;
        }

        sum += power;
        num /= 10;
    }

    if(temp == sum)
        printf("%d is an Armstrong number\n", temp);
    else
        printf("%d is not an Armstrong number\n", temp);

    return 0;
}
  

πŸ“˜ Explanation:

This program checks if a number is an Armstrong number without using the pow() function from math.h. Instead, it calculates the power of each digit manually with a for loop.

  • First count the total digits of the number.
  • Extract each digit using modulus (%).
  • Compute digit^n by multiplying in a loop.
  • Add all powered digits.
  • Compare with the original number → if equal, it’s an Armstrong number.

🧾 Sample Output:

Enter the number:
9474
9474 is an Armstrong number

Enter the number:
123
123 is not an Armstrong number
  

πŸ”‘ Keywords:

Armstrong number without pow, C program Armstrong check manually, Armstrong number code with loop, interview C programs, Armstrong logic in C

πŸ“Œ Hashtags:

#CProgramming #ArmstrongNumber #WithoutPow #CodingForBeginners #InterviewPrep

πŸ” Search Description:

This C program checks whether a number is an Armstrong number without using pow(). Instead, digit powers are calculated manually with a loop.

Comments

Popular Posts

πŸŒ™