home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_200 / 247_01 / hail.cpp < prev    next >
Text File  |  1989-04-19  |  640b  |  31 lines

  1. /*
  2.  *   Program to investigate hailstone numbers.
  3.  *   Gruenberger F. 'Computer Recreations' Scientific American. April 1984.
  4.  */
  5.  
  6. #include <stream.hpp>
  7. #include "big.hpp"
  8.  
  9. miracl precision=100;
  10.  
  11. main()
  12. {  /*  hailstone numbers  */
  13.     int iter;
  14.     Big x,y,r,mx;
  15.     iter=0;
  16.     cout << "number = ";
  17.     cin >> x;
  18.     do
  19.     {
  20.         if (x>mx) mx=x;
  21.         r=x%2; 
  22.         if (r!=0) x=3*x+1;
  23.         else      x/=2;
  24.         cout << x << "\n";
  25.         iter++;
  26.     } while (x!=1);
  27.     cout <<  "path length = " << iter << "\n";
  28.     cout <<  "maximum = " << mx << "\n";
  29.  
  30.