fork download
  1. #include <stdio.h>
  2.  
  3. void printCollatz(int x)
  4. {
  5. printf("%d", x);
  6. while (x > 1)
  7. {
  8. if ((x % 2) == 0)
  9. {
  10. x = x / 2;
  11. }
  12. else
  13. {
  14. x = (3 * x) + 1;
  15. }
  16. printf(", %d", x);
  17. }
  18. printf("\n");
  19. }
  20.  
  21. int main()
  22. {
  23. int rangeValue = 12;
  24. for (int i = 1; i <= rangeValue; ++i)
  25. {
  26. printCollatz(i);
  27. }
  28. return 0;
  29. }
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
1
2, 1
3, 10, 5, 16, 8, 4, 2, 1
4, 2, 1
5, 16, 8, 4, 2, 1
6, 3, 10, 5, 16, 8, 4, 2, 1
7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1
8, 4, 2, 1
9, 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1
10, 5, 16, 8, 4, 2, 1
11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1
12, 6, 3, 10, 5, 16, 8, 4, 2, 1