programming-examples/c-sharp/Mathematics/C# Program to calculate the series sin(x).cs

41 lines
965 B
C#
Raw Normal View History

2019-11-15 12:59:38 +01:00
/*
* C# Program to calculate the series sin(x)=x-x^3/3!+x^5/!-x^7/7!+......
*/
using System;
class sine
{
int deg, n;
public void readdata()
{
Console.WriteLine("Enter the Number of Terms:");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the Angle in Degrees:");
deg = Convert.ToInt32(Console.ReadLine());
}
public void sineseries()
{
float x, s = 0.0f, t;
x = (float)Math.PI * deg / 180f;
s = x;
t = x;
for (int i = 1; i <= n; i++)
{
t = (-t * x * x) / ((2 * i) * (2 * i + 1));
s = s + t;
}
Console.WriteLine("Sin({0})={1}", deg, s);
}
public static void Main()
{
sine s = new sine();
s.readdata();
s.sineseries();
}
}
/*
Enter the Number of Terms:
20
Enter the Angle in Degrees:
90
Sin(90)=0.99999994