fork download
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int n, sum, digit;
  6.  
  7. printf("Enter a number: ");
  8. scanf("%d", &n);
  9.  
  10. while (n >= 10)
  11. {
  12. sum = 0;
  13.  
  14. while (n > 0)
  15. {
  16. digit = n % 10;
  17. sum = sum + digit;
  18. n = n / 10;
  19. }
  20.  
  21. n = sum;
  22. }
  23.  
  24. if (n == 1)
  25. printf("The number is a Magic Number.");
  26. else
  27. printf("The number is not a Magic Number.");
  28.  
  29. return 0;
  30. }
  31.  
  32.  
Success #stdin #stdout 0s 5320KB
stdin
172
stdout
Enter a number: The number is a Magic Number.