fork(1) download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static int Fact( int n )
  6. {
  7. if( n == 0 ) return 1;
  8. return n*Fact( n-1);
  9. }
  10.  
  11. public static double Term( double x, int n )
  12. {
  13. return Math.Pow( x, n )/ Fact(n);
  14. }
  15.  
  16. public static void Main()
  17. {
  18. const double eps = 0.00001;
  19. double exp = 0;
  20. int i = 0;
  21. double term;
  22. do
  23. {
  24. term = Term( 1, i++ );
  25. exp += term;
  26. }
  27. while( term > eps );
  28.  
  29. Console.WriteLine( exp );
  30. Console.WriteLine( Math.Exp(1) );
  31.  
  32. }
  33. }
Success #stdin #stdout 0.03s 33872KB
stdin
Standard input is empty
stdout
2.71828152557319
2.71828182845905