The C# Program: tpk.cs

  1 //tpk.cs -- Knuth's TPK program in the C# programming language
  2 
  3 using System;
  4 
  5 class tpk {
  6 
  7    // f(x) = sqrt(|x|) + 5*x**3
  8    private static double f (double x) {
  9       return Math.Sqrt (Math.Abs(x))+ 5*(Math.Pow(x,3));
 10    }
 11 
 12    static int Main(){
 13       double[] A = new double[11];
 14 
 15       // read in the values of the array A
 16       for (int i=0; i<11; i++) {
 17          A[i] = Convert.ToDouble (Console.ReadLine());
 18       }
 19 
 20       // In reverse order, apply "f" to each element of "A" and print
 21       for (int i=10; i >= 0; i--) {
 22          double y = f(A[i]);
 23          if (y > 400.0) {
 24             Console.WriteLine ("{0} TOO LARGE", i);
 25          } else {
 26             Console.WriteLine (i.ToString()+" "+y.ToString());
 27          }
 28       }
 29 
 30       return 0;
 31    }
 32 }