# C# - Calculate the Cosine(X)

Here, we are going to learn about the Cosine(X), and learn how to calculate the Cosine(X) using a predefined method in C#? By Nidhi Last updated : April 15, 2023

Here, we calculate the Cosine(X) using Cos() method of Math class.

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

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.

Comments and Discussions!

Student's Section
Subscribe

Copyright © 2024 www.includehelp.com. All rights reserved.