# WAP in C to print out all Armstrong numbers between 1 and 500

The Program in C that prints out all Armstrong numbers between 1 and 500 are given below:

``````#include <stdio.h>
#include <math.h>

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

printf("Armstrong numbers between 1 and 500 are: \n");

for(num = 1; num <= 500; num++)
{
originalNum = num;

while (originalNum != 0)
{
originalNum /= 10;
++n;
}

originalNum = num;

while (originalNum != 0)
{
remainder = originalNum % 10;
result += pow(remainder, n);
originalNum /= 10;
}

if (result == num)
printf("%d ", num);

n = 0;
result = 0;
}
return 0;
}
``````

## Output:

Armstrong numbers between 1 and 500 are:
1 2 3 4 5 6 7 8 9 153 370 371 407

## Pro-Tips💡

This program uses two nested while loops to check if each number between 1 and 500 is an Armstrong number.

The outer loop iterates through all the numbers between 1 and 500, and the inner loop checks if the number is an Armstrong number by calculating the sum of its digits raised to the power of the number of digits.

If the number is an Armstrong number, it is printed to the screen.

### Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

### Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

### Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly. Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

## C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

## C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

## C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

## C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

## C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

## C# Program to Delete Element at Desired position From Array

The Program in C# Program to Delete Element at Desired position From Array is given below: Output: Hello Codeauri Family, enter the number of elements in the array:4Enter…

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X