Home » C Program To Check An Armstrong Number

C Program To Check An Armstrong Number

This C program checks an input number whether it is an Armstrong number on not and prints the results. An Armstrong number is special number sum of the nth power of its every digit is equal to the original number. The n is the number of digits in the input number. This concept is explained in more detail in the problem section.

We compiled the program using Dev C++ version 4 compiler installed on Windows 7 64-bit. You can use a different compiler if you like after modifying the source code according to your compiler specifications. This is necessary to compile an error-free program.

You must be familiar with following C programming concept to understand this example.

Problem Definition

What is an Armstrong Number?

Suppose there is a number N, this number has n digits, if

  1. We take each digit of the number N separately
  2. Compute nth power of each digit, and
  3. Take the sum, S of all the power obtained in step 2.
  4. If the sum is equal to original number, N;
  5. Then the given number N is an Armstrong number.

For Example

371 = 3^3 + 7^3 + 1^3
 27 + 343 + 1
371

The number N in above example is 371 and number of digits n = 3. So we raise each of the digits of 371 to power to 3. Then the sum of all power is equal to the original number if the number is an Armstrong number.

(adsbygoogle = window.adsbygoogle || []).push({}); </script

Please support us by disabling your adblocker or whitelist this site from your adblocker. Thanks!

turn of adblocker imag

(adsbygoogle = window.adsbygoogle || []).push({});