Skip to content

Instantly share code, notes, and snippets.

@longtth
Created August 23, 2019 03:02
Show Gist options
  • Save longtth/ab39ce33d01f6625d83deeb377027be2 to your computer and use it in GitHub Desktop.
Save longtth/ab39ce33d01f6625d83deeb377027be2 to your computer and use it in GitHub Desktop.
S = 1 + x^2/2! + x^4/4! +...+ x^2n/2n!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GiaiBaiTap
{
class Program
{
static void Main(string[] args)
{
int x = 3;
int n = 4;
Console.WriteLine(TinhS(x,n));
Console.ReadLine();
}
static double TinhS(int x, int n)
{
double tmp = 1;
for (int i = 1; i <= n; i++)
{
return tmp += Math.Pow(x, 2 * i) / GiaiThua(2 * i);
}
return tmp;
}
static long GiaiThua(int x)
{
long tmp = 1;
for (int i = 1; i <= x; i++)
{
tmp *= i;
}
return tmp;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment