Skip to main content

Featured

C Pattern Programs: Square Number and Alphabet Patterns Explained

πŸ”· Square Star Pattern πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { printf("* ");//keep"* " } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Column-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = num; i >= 1; i--) { for(int j = num; j >= 1; j--) { printf("%c ", j + 64);//%c for Character and 64 will be ASIIC VALUE } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Row-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; ...

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

πŸŒ™