Created
February 15, 2016 19:08
-
-
Save fotonmoton/1c9e672900d393a3aee8 to your computer and use it in GitHub Desktop.
cos recursion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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