Q:

C# program to find the value of sin(x)

belongs to collection: C# Basic Programs | basics

0

sin(x)=x-x^3/3!+x^5/5-x^7/7!

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to find the value of SIN(x), is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//Program to calculate the series of sin(x) in C#

using System;

class Sine
{
    static double CalculateSinX(int deg, int terms)
    {
        double x;
        double result;
        double temp;

        int loop;
        x = Math.PI * deg / 180f;
        result = x;
        temp   = x;

        for (loop = 1; loop <= terms; loop++)
        {
            temp = (-temp * x * x) / ((2 * loop) * (2 * loop + 1));
            result = result + temp;
        }

        return result;
    }
    public static void Main()
    {
        int degree  =   0;
        int terms   =   0;

        double result = 0.0;

        Console.Write("Enter the angle in Degrees:");
        degree = int.Parse(Console.ReadLine());

        Console.Write("Enter the number of terms:");
        terms = int.Parse(Console.ReadLine());

        result = CalculateSinX(degree, terms);
        Console.WriteLine("Sin({0})={1}", degree, result);
    }
}

Output:

Enter the angle in Degrees:90
Enter the number of terms:20
Sin(90)=1
Press any key to continue . . .

Explanation:

Here, we created a class Sin that contains two static methods CalculateSinX() and Main().

The CalculateSinX() method is used to calculate the value of SIN() based on a specified degree and number terms using the below series.

sin(x)=x-x^3/3!+x^5/5-x^7/7!

In the Main() method, we read the value of the degree and terms from the user and the calculate value of SIN(X) using CalculateSinX() and print the result on the console screen.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | basics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to demonstrate the trigonometry angles ... >>
<< C# program to find the greatest common divisor (GC...