Check Whether a Number is Armstrong or Not in C Program

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

int main()
{
int number, originalNumber, remainder, result = 0, n = 0 ;

printf("Enter an integer: ");
scanf("%d", &number);

originalNumber = number;

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

originalNumber = number;

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

if(result == number)
printf("%d is an Armstrong number.", number);
else
printf("%d is not an Armstrong number.", number);

return 0;
}

Example:

153 = 1^3 + 5^3 + 3^3

=1 + 125 + 27

=153 / / It is Armstrong

 

Other Related Topic

Reversing Number (Click Here)

Palindrome or Not in C program (Click Here)

Positive, Negative or Zero in C Program (Click Here)

Leave a Reply

Your email address will not be published. Required fields are marked *

Enter Captcha Here : *

Reload Image