vacendak

Pi Decimals

Mar 19th, 2020
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(int argc, char *argv[])
  4. {
  5.     int p, q, d;
  6.     int j, tot = 0;
  7.     int k, t, a[100000];
  8.     int num;
  9.     char o[1]="";
  10.  
  11.     principio:
  12.  
  13.     k = 4000;
  14.     t = 1000;
  15.  
  16.     printf("\n\nInput number of decimals desired: ");
  17.     scanf(" %i", &tot);
  18.  
  19.     if (tot%3 != 0)
  20.         tot++;
  21.  
  22.     printf("\n\n\tPI = 3,");
  23.     num=(tot/3) + 3;
  24.  
  25.     while(k > 1)
  26.     {
  27.         k--;
  28.         q = 0;
  29.         a[0] += 2;
  30.         p = 1 + 2 * k;
  31.  
  32.         for(j = 0; j < num; j++)
  33.         {
  34.             if((j > 2 && k == 1) || k == 0)
  35.             {
  36.                 d = a[j - 2]%t + (q / p) / t;
  37.                 printf("%.3ld",d);
  38.             }
  39.             q = a[j] * k + q%p * t;
  40.             a[j] = q / p;
  41.         }
  42.     }
  43.     tot = (num-3) * 3;
  44.  
  45.     printf("\n\n\tNumber of decimals: %i", tot);
  46.     printf("\n");
  47.     printf("\n\tWanna try again? (y/n): ");
  48.     scanf(" %c", &o);
  49.     if (o[0]=='y')
  50.         goto principio;
  51.  
  52.     printf("\n\n");
  53.  
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment