• Home
  • Math Class and Functions

Math Class and Functions

Agenda

C# Math Class and Methods

C# Math Class and Methods - Contd

C# Math Class and Methods - Contd

Console.WriteLine(Math.Truncate(20.55)); // output: 20
Console.WriteLine(Math.Log(3));
// 5 is base and 3 is power
double pow_ab = Math.Pow(5, 3);

// Print the result in Console
Console.WriteLine(pow_ab);
Console.WriteLine(Math.Pow(8, 2));

double pi_value = Math.PI;
Console.WriteLine(pi_value);
// input radius value of a cylinder
double radius = 10;
// input length value of a cylinder
double length = 15;
// calculate the area using PI of a cylinder
double area = radius * radius * Math.PI;
// Calculate volume of a cylinder
double volume = area * length;

// print area and volume of cylinder in console
Console.WriteLine("Area of cylinder is : " + area);
Console.WriteLine("Volume of cylinder is : " + volume);

double x = -3.78;
double y = 16;
Console.WriteLine(Math.Round(5.88)); //6
Console.WriteLine(Math.Round(5.38)); //5

Console.WriteLine(Math.Floor(x));
Console.WriteLine(Math.Floor(5.38)); //5
Console.WriteLine(Math.Ceiling(x)); //-4
Console.WriteLine(Math.Ceiling(5.38)); //5

Console.WriteLine(Math.Max(10, 20));
Console.WriteLine(Math.Max(10.677, 2.7889));
Console.WriteLine(Math.Min(10, 20));
Console.WriteLine(Math.Min(10.677, 2.7889));
Console.WriteLine(Math.Abs(x));
Console.WriteLine(Math.Round(x));
Console.WriteLine(Math.Sqrt(y));