Q:

C# program to calculate the Cosine(X) using a predefined method

belongs to collection: C# Basic Programs | basics

0

C# program to calculate the Cosine(X) using a predefined method

All Answers

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

Program:

The source code to calculate the Cosine(X) using the predefined method is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to calculate the Cos(X) 
//using the predefined method. 

using System;

class Demo
{
    
    static void Main(string[] args)
    {
        double val = 0.0F;

        while(val<=5)
        {
            Console.WriteLine("Cos({0}) => {1}", val, Math.Cos(val));
            val++;
        }
        Console.WriteLine();
    }
}

Output:

Cos(0) => 1
Cos(1) => 0.54030230586814
Cos(2) => -0.416146836547142
Cos(3) => -0.989992496600445
Cos(4) => -0.653643620863612
Cos(5) => 0.283662185463226

Press any key to continue . . .

Explanation:

Here, we created a class Demo that contains the Main() method, the Main() is the entry point of the program, here we calculated the Cosine(X) using the predefined method Cos() of Math class. Here we calculated Cosine(X) for values 0 to 5 and print the results 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 calculate the Cosine(X) without usin... >>
<< C# program to calculate the compound interest...