# C program to check the input integer number is an Armstrong number using the for loops & while loops

__C program__ to check the input integer number is an Armstrong number using the for loops & while loops. In this program you will learn how to check the input number is an Armstrong number using the for loops & while loops.

## Formula to check the Armstrong numbers:

**abcd... = a**If this condition is true then It's an Armstrong number

^{n}+ b^{n}+ c^{n}+ d^{n}+ [**]**

1. __C program__ to check the input integer number is an Armstrong number using the for loop:

```
// C program to check the input integer number is an Armstrong number using the for loop
#include <stdio.h>
#include <math.h>
int main() {
int x, y, rem, n = 0;
float r = 0.0;
// x - denotes the input number
// y - denotes the storage of original input number to check
// rem - denotes the reminder
// r - denotes the result variable
printf("-----Enter the integer number-----\n");
scanf("%d", &x);
y = x;
// store the number of digits of x in n
for (y = x; y != 0; ++n) {
y /= 10;
}
for (y = x; y != 0; y /= 10) {
rem = y % 10;
// store the sum of the power of individual digits in r
r += pow(rem, n);
}
// if x is equal to r, the number is an Armstrong number
if ((int) r == x) {
printf("%d is an Armstrong number.\n", x);
} else {
printf("%d is not an Armstrong number.\n", x);
}
return 0;
}
```

**Output:**

-----Enter the integer number-----

9474

9474 is an Armstrong number.

9474

9474 is an Armstrong number.

## 2. __C program__ to check the input integer number is an Armstrong number using the while loop:

```
// C program to check the input integer number is an Armstrong number using the while loop
#include <stdio.h>
#include <math.h>
int main() {
int x, y, z, rem, n = 0;
float r = 0.0;
// x - denotes the input number
// y & z - denotes the storage of original input number to check
// rem - denotes the reminder
// r - denotes the result variable
printf("-----Enter the integer number-----\n");
scanf("%d", &x);
z = y = x;
while (y != 0) {
y /= 10;
++n;
}
while (z != 0) {
rem = z % 10;
r += pow(rem, n);
z /= 10;
}
// if x is equal to r, the number is an Armstrong number
if ((int) r == x) {
printf("%d is an Armstrong number.\n", x);
} else {
printf("%d is not an Armstrong number.\n", x);
}
return 0;
}
```

**Output:**

-----Enter the integer number-----

9474

9474 is an Armstrong number.

9474

9474 is an Armstrong number.

## 3. __C program__ to check the input integer number is an Armstrong number without using power function:

```
// C program to check the input integer number is an Armstrong number without using the power function
#include <stdio.h>
int main() {
int x, y, z, rem = 1, rem2 = 1, n = 0, m = 0;
float r = 0.00;
// x - denotes the input number
// y & z - denotes the storage of original input number to check
// rem & rem2 - denotes the reminder values
// r - denotes the result variable
printf("-----Enter the integer number-----\n");
scanf("%d", &x);
z = y = x;
while (y != 0) {
y /= 10;
++n;
}
m = n;
while (z != 0) {
rem = z % 10;
rem2 = 1;
while (n > 0) {
rem2 *= rem;
--n;
}
n = m;
r += rem2;
z /= 10;
}
// if x is equal to r, the number is an Armstrong number
if ((int) r == x) {
printf("%d is an Armstrong number.\n", x);
} else {
printf("%d is not an Armstrong number.\n", x);
}
return 0;
}
```

**Output:**

-----Enter the integer number-----

9474

9474 is an Armstrong number.

9474

9474 is an Armstrong number.

## Tags:

# write a program to check an input number is an Armstrong number in c using the function

# write a program to check an input number is an Armstrong number in c using for loop

# write a program to check input number is an Armstrong number in c between 1 to 1000