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();
}
}
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.
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.
Output:
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.