
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

runner%
(^) cat th.c
/* th: three/halves program.
Always ends up
at 1.
Written by NR Wagner, 28 Mar 1997 */
{ int main()void run(int n);#include <stdio.h> while(scanf("%i", &n) != EOF)int n; run(n);
return 0;
{ void run(int n)/* run: follow one run to the end */} while (n != 1) { if ((n%2) == 0)printf("%i ", n); n = n/2;
else n = (3*n + 1)/2;
printf("%i\n", n);}
runner% }
(^) cc -o th th.c
runner%
(^) th
runner% 30 15 23 35 53 80 40 20 10 5 8 4 2 1 30 29 44 22 11 17 26 13 20 10 5 8 4 2 1 29 28 14 7 11 17 26 13 20 10 5 8 4 2 1 28 61 92 46 23 35 53 80 40 20 10 5 8 4 2 14616 2308 1154 577 866 433 650 325 488 244 1221079 1619 2429 3644 1822 911 1367 2051 3077334 167 251 377 566 283 425 638 319 479 719206 103 155 233 350 175 263 395 593 890 445 668 27 41 62 31 47 71 107 161 242 121 182 91 137 27 26 13 20 10 5 8 4 2 1 26 25 38 19 29 44 22 11 17 26 13 20 10 5 8 4 2 1 25 24 12 6 3 5 8 4 2 1 24 23 35 53 80 40 20 10 5 8 4 2 1 23 22 11 17 26 13 20 10 5 8 4 2 1 22 21 32 16 8 4 2 1 21 20 10 5 8 4 2 1 20 19 29 44 22 11 17 26 13 20 10 5 8 4 2 1 19 18 9 14 7 11 17 26 13 20 10 5 8 4 2 1 18 17 26 13 20 10 5 8 4 2 1 17 16 8 4 2 1 16 15 23 35 53 80 40 20 10 5 8 4 2 1 15 14 7 11 17 26 13 20 10 5 8 4 2 1 14 13 20 10 5 8 4 2 1 13 12 6 3 5 8 4 2 1 12 11 17 26 13 20 10 5 8 4 2 1 11 10 5 8 4 2 1 10