home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 135_01 / e.c < prev    next >
Text File  |  1985-03-10  |  1KB  |  52 lines

  1. /*
  2.     e.c---demonstration of VLI math package.  Compute
  3.     'e' with variable precision.  There is an arbitrary
  4.     limit on the size of e simply because 50 digits of
  5.     precision is all there is in my copy of "CRC Standard
  6.     Math Tables", 25th edition.  I would also point out
  7.     that at level 50, t1 and r are over 110 characters long,
  8.     so if you wish to expand further, adjust #define MAX.
  9.  
  10.     build:
  11.  
  12.         n>cc e
  13.         n>clink e ratc vli math
  14.  
  15.     by Hugh S. Myers
  16.  
  17.     4/1/84
  18.     4/3/84
  19. */
  20.  
  21. #include <bdscio.h>
  22. #define MAX 256
  23. #define LIMIT 3
  24.  
  25. main()
  26. {
  27.     char one[MAX], s[LIMIT], r[MAX], t1[MAX], t2[MAX];
  28.     int i, n;
  29.  
  30.     puts("e.c a program to compute 'e'\n");
  31.     forever {
  32.         puts("accurate to how many digits(0>n>50)? ");
  33.         getline(s,LIMIT);
  34.         n=atoi(s);
  35.         if(n<1 || n>50)
  36.             continue;    
  37.         strcpy(one,"1.0");
  38.         pad(one,n+10);
  39.         strcpy(r,"2");
  40.         strcpy(t2,"2");
  41.         for(i=0;i<n+5;i++) {
  42.             strcpy(t1,facl(t2));
  43.             strcpy(t1,rdiv(one,t1));
  44.             strcpy(r,radd(r,t1));
  45.             strcpy(t2,incrl(t2));
  46.             putch('.');
  47.         }
  48.         putch('\n');
  49.         r[n+2]='\0';
  50.         printf("e= %s\n",r);
  51.     }
  52. }