#include <stdio.h>
#include <math.h>
int main() {
int number, temp, remainder, i, power, digits = 0, sum = 0;
printf("Enter a number : ");
scanf("%d", &number);
temp = number;
while (temp != 0) { // complete the condition to iterate the Loop
digits = digits + 1; // increment the digits
temp = temp / 10; //calculate the temp value
}
temp = number;
while (temp > 0) { // complete the condition to iterate the Loop
remainder = temp % 10;
sum = sum + pow(remainder, digits);
temp = temp / 10;
}
if (number == sum) {
printf("The given number %d is an armstrong number\n", number);
} else {
printf("The given number %d is not an armstrong number\n", number);
}
return 0;
}
Output:
Comments
Leave a comment