My issue
i want this answer
My code
#include <stdio.h>
#include <math.h>
// Function to check if a number is Armstrong
int isArmstrong(int n) {
int original = n, sum = 0, digits = 0;
// Calculate the number of digits
while (n > 0) {
digits++;
n /= 10;
}
n = original; // Reset n to the original number
// Calculate the Armstrong sum
while (n > 0) {
int digit = n % 10;
sum += pow(digit, digits);
n /= 10;
}
// Check if the sum is equal to the original number
return sum == original;
}
int main() {
int number;
// Read input from the user
printf("Enter a number: ");
scanf("%d", &number);
// Check and print the result
if (isArmstrong(number)) {
printf("Armstrong\n");
} else {
printf("Not Armstrong\n");
}
return 0;
}
Learning course: Roadmap to 3*
Problem Link: https://www.codechef.com/learn/course/klu-roadmap-3star/KLURMP300B/problems/LPYAS151