Answer:
#include <stdio.h>
#include <math.h>
int is_armstrong(int n) {
int cubedSum = 0;
int r = n;
while (r) {
cubedSum += (int)pow(r % 10, 3);
r = r / 10;
}
return cubedSum == n;
}
int stack_count(int n) {
int sum = 0;
while (n) {
sum += n % 10;
n = n / 10;
}
return sum;
}
int is_magical(int n) {
while (n > 9) {
n = stack_count(n);
printf("%d ", n);
}
return n == 1;
}
int main()
{
int input = 0;
int isMagical, isArmstrong;
while (true) {
printf("Enter a number: ");
scanf_s("%d", &input, sizeof(int));
if (input == -1) break;
isArmstrong = is_armstrong(input);
isMagical = is_magical(input);
if (isArmstrong && isMagical) {
printf("%d is both an armstrong and a magical number.\n", input);
} else if (isArmstrong) {
printf("%d is an armstrong number\n", input);
} else if (isMagical) {
printf("%d is a magical number\n", input);
} else {
printf("%d is neither an armstrong or a magical number.\n", input);
}
}
}
Explanation:
Here is a starting point. What's the definition of a magical number?