Skip to content

Instantly share code, notes, and snippets.

@fotonmoton
Created February 15, 2016 19:08
Show Gist options
  • Save fotonmoton/1c9e672900d393a3aee8 to your computer and use it in GitHub Desktop.
Save fotonmoton/1c9e672900d393a3aee8 to your computer and use it in GitHub Desktop.
cos recursion
using System;
namespace cos_recursion
{
class Program
{
public static double power(double x, double n)
{
if (n == 0)
{
return 1;
}
else
{
return x * power(x, n - 1);
}
}
public static double factorial(double n)
{
if(n <=1 )
{
return 1;
}
else
{
return n * factorial(n - 1);
}
}
public static double cosinus(double x, double n)
{
if (n == 0)
{
return 1;
}
else
{
return (power(-1, n) / factorial(2 * n)) * power(x, 2 * n) + cosinus(x, n - 1);
}
}
static void Main(string[] args)
{
Console.WriteLine(cosinus(0.3,10));
Console.WriteLine(Math.Cos(0.3));
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment