// TAU2.C // Calculates a series of tau values // Author: Peter Meyer // Last mod.: 1999-01-12 #include <string.h> #include <stdio.h> #include <math.h> #include <conio.h> #define VERBOSE 0 double tau_1(int n); double tau_2(int n, int m); /*----------------------------*/ void main(int argc,char *argv[]) { int n; double this_tau, last_tau; printf("\nThis program calculates the series of tau(n), where" "\ntau(n) = sqrt(1^n + sqrt(2^n + sqrt(3^n + sqrt(4^n + ..,))))\n"); last_tau = 0; for ( n=0; n<15; n++ ) { this_tau = tau_1(n); printf("\ntau(%d)%s = %19.16f",n,(n<10?" ":""),this_tau); if ( last_tau > 0 ) printf(" diff = %2.6f",this_tau - last_tau); last_tau = this_tau; #if VERBOSE getch(); #endif } printf("\n"); } /*---------------*/ double tau_1(int n) { int m=2; double t0, t1=0; do { t0 = t1; t1 = tau_2(n,m++); #if VERBOSE printf("\n%18.16f",t1); #endif } while ( t1 != t0 ); return ( t1 ); } /*----------------------*/ double tau_2(int n, int m) { int i; double x; x = sqrt(pow((double)m,(double)n)); // x = sqrt(m^n) for ( i=m-1; i>=1; i-- ) x = sqrt(pow((double)i,(double)n) + x); // x = sqrt(i^n + x) return ( x ); }