#include <stdio.h>
#include <math.h>
// Function to calculate the number of digits in a given number
int countDigits(int num);
// Function to check if a number is an Armstrong number
int isArmstrong(int num);
int main() {
int num;
// Input the number from the user
printf("Enter a number: ");
scanf("%d", &num);
// Check if the number is an Armstrong number and display the result
if (isArmstrong(num)) {
printf("%d is an Armstrong number.\n", num);
} else {
printf("%d is not an Armstrong number.\n", num);
}
return 0;
}
int countDigits(int num) {
int count = 0;
// Count the number of digits using a loop
while (num != 0) {
num /= 10;
++count;
}
return count;
}
int isArmstrong(int num) {
int originalNum, remainder, result = 0, n = 0;
// Store the input number in originalNum
originalNum = num;
// Count the number of digits in the number
n = countDigits(num);
// Calculate the sum of nth power of individual digits
while (originalNum != 0) {
remainder = originalNum % 10;
result += pow(remainder, n);
originalNum /= 10;
}
// Check if the result is equal to the original number
if (result == num) {
return 1; // It is an Armstrong number
} else {
return 0; // It is not an Armstrong number
}
}