Write a program to check whether a given number is Armstrong number or not.

Palak Patel08 May 2026
Write a program to check whether a given number is Armstrong number or not.

Write a Program to Check Whether a Given Number is Armstrong Number or Not

An Armstrong Number is a number in which the sum of cubes of its digits is equal to the original number.

For example:

153 = (1 × 1 × 1) + (5 × 5 × 5) + (3 × 3 × 3)

153 = 1 + 125 + 27 = 153

Therefore, 153 is an Armstrong Number.

Algorithm

  • Take a number as input.
  • Store the original number in another variable.
  • Extract digits one by one using modulus operator (%).
  • Find cube of each digit and add them.
  • Compare the sum with the original number.
  • If both are equal, the number is Armstrong Number.

C Program

#include <stdio.h>

int main()
{
    int num, originalNum, remainder;
    int result = 0;

    printf("Enter a number: ");
    scanf("%d", &num);

    originalNum = num;

    while(originalNum != 0)
    {
        remainder = originalNum % 10;

        result = result + (remainder * remainder * remainder);

        originalNum = originalNum / 10;
    }

    if(result == num)
    {
        printf("%d is an Armstrong Number", num);
    }
    else
    {
        printf("%d is not an Armstrong Number", num);
    }

    return 0;
}

Output Example

Enter a number: 153
153 is an Armstrong Number

Explanation of Program

Statement Purpose
originalNum % 10 Extracts last digit
remainder * remainder * remainder Finds cube of digit
originalNum / 10 Removes last digit
if(result == num) Checks Armstrong condition

Conclusion

This program is useful for understanding loops, conditions, and arithmetic operations in C programming.

Armstrong Number programs are frequently asked in practical exams and programming interviews.

Comments

0/1000

No comments yet. Be the first!