Use Mathematical functions from Math class - CSharp Language Basics

CSharp examples for Language Basics:Math

Description

Use Mathematical functions from Math class

Demo Code

using System;//from   w  w  w.  j  av  a  2  s .  c  o m
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
   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.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


Related Tutorials