/* Pi Spigot from April '95 Math Monthly ---------------------- The program basically evaluates n terms of a series for pi by starting with the last term and multiplying by 10 and carrying the remainder to the next term, reading off the ones digit, and repeating until all numerators are zeroed. Check out the issue for a more detailed explanation. Improved output by Robert Simms, of Salsibury State U (MD) and Clemson U. (SC) Language: Java (manually converted from C, manually converted from Pascal) */ public class piRadix { public static void main(String[] args) { int n; if(args.length>=1) { n = Integer.valueOf(args[0]).intValue() +2; } else { n = Integer.parseInt( IO.readLn("Enter the desired number of digits: ") ); } new piRadix(n); } private void digout(int count, int digit) { System.out.print(digit); if(count%100==0) { if(count==0) { System.out.println(); } else { System.out.println(" (" +count +")"); } } if(count%20==0) { System.out.println(); } else if(count%5==0) { System.out.print(" "); } } piRadix(int n) { int count, i, j, k, len, maxcount, nines, predigit, q, x; maxcount = n +3; len = (int) 10*maxcount/3; int[] a = new int[len]; count = -2; predigit = 0; nines = 0; for(j=0; j=0; i--) { x = 10*(a[i]) +q*(i+1); a[i] = x % (2*i+1); q = (int) x/(2*i+1); } a[0] = q % 10; q = (int) q/10; switch(q) { case 10: digout(++count, predigit +1); for(k=0; k