Sin 을 처리하는 함수를 유사하게 만들어봅니다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace Ruru.Math
{
public class Sin
{
public static double GetSin(double x)
{
double sum = 0.0;
double r = 1.0;for (int i = 1; i < 13; i++)
{
r *= x / (1.0 * i);switch (i % 4)
{
case 1: sum += r; break; // 1
case 3: sum += (-1) * r; break; // -1
case 2:
case 4: break; // 0
}
}
return sum;
}public static void PrintSin()
{
for (int i = 0; i < 180; i++)
Console.WriteLine("Sin({0}) = {1}", i, GetSin(System.Math.PI*i/180.0));
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace Ruru.Math
{
class SinMain
{
static void Main(string[] args)
{
Sin.PrintSin();
}
}
}
'Development > .NET' 카테고리의 다른 글
| C#으로 짜본 야구게임 (1) | 2007.07.16 |
|---|---|
| 4의배수 크기 마방진 알고리즘 (1) | 2007.07.13 |
| Taylor Series - Exp(x) 구현 (0) | 2007.07.12 |
| 주민등록번호 유효성의 체크 로직 (2) | 2007.07.04 |
| 만져보고 싶은 장난감이 생기다. (1) | 2007.07.04 |