fork download
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. int digital_root(int n)
  8. {
  9. int length = 1;
  10. int divider = 1000000;
  11. int d = 10;
  12. int result = 0;
  13. while (d > 9)
  14. {
  15. d = n % divider;
  16. if (d != n)
  17. {
  18. length++;
  19. }
  20.  
  21. divider /= 10;
  22. }
  23. divider = pow(10, length - 1);
  24. d = 10;
  25.  
  26. int *arr = new int[length];
  27.  
  28. for (int i = 0; i < length; i++)
  29. {
  30. arr[i] = floor(n / divider);
  31. result += arr[i];
  32. n %= divider;
  33. divider /= 10;
  34. cout << "ELEM" << i << "=" << arr[i] << endl;
  35. }
  36.  
  37. if (result < 10)
  38. {
  39. return result;
  40. }
  41. else
  42. {
  43. digital_root(result);
  44. }
  45.  
  46. cout << "Result\t" << result << endl;
  47. return result;
  48. }
  49.  
  50. int main()
  51. {
  52. int n;
  53. int result;
  54. cin >> n;
  55. digital_root(n);
  56. cout << "Result\t" << result << endl;
  57.  
  58. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:17: fatal error: pch.h: No such file or directory
 #include "pch.h"
                 ^
compilation terminated.
stdout
Standard output is empty