CSharp - Write program to calculate the sine and the square root of the entered numbers

Requirements

Perform the complex operations using built-in (predefined) mathematical functions.

You will calculate the sine and the square root of the entered numbers.

Hint

To calculate values of mathematical functions, you use the Math type.

Math type contains many useful functions.

Sin function requires the angle to be specified in radians.

If your input is in degrees, you need to make a conversion.

If the user enters a negative number, its square root cannot be calculated, and the result becomes NaN ("not-a-number").

Demo

using System;
class Program/* w ww. ja  v  a  2  s . c om*/
{
    static void Main(string[] args)
    {
        // Input of angle 
        Console.Write("Enter an angle in degrees: ");
        string input = Console.ReadLine();
        double angleInDegrees = Convert.ToDouble(input);

        // Calculation and output of sine value 
        double angleInRadians = angleInDegrees * Math.PI / 180;
        double result = Math.Sin(angleInRadians);
        Console.WriteLine("Sine of the angle is: " + result);

        // Input of a positive number 
        Console.WriteLine();
        Console.Write("Enter a positive number: ");
        input = Console.ReadLine();
        double number = Convert.ToDouble(input);

        // Calculation and output of square root 
        Console.WriteLine("Square root of the number is: " + Math.Sqrt(number));
    }
}

Result