Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

C# Math:


Sure! In C#, the System.Math class provides a wide range of mathematical functions for performing common mathematical operations. Here's a simple explanation of some of the functions along with examples:

  1. Abs(): Returns the absolute value of a number.
  2. Example

    using System;

    class Program
    {
    static void Main()
    {
    int number = -10;
    int absoluteValue = Math.Abs(number);
    Console.WriteLine("Absolute value of " + number + " is: " + absoluteValue);
    }
    }

    OutPut

    Absolute value of -10 is: 10

  3. Sqrt(): Returns the square root of a number.
  4. Example

    using System;

    class Program
    {
    static void Main()
    {
    double number = 25;
    double squareRoot = Math.Sqrt(number);
    Console.WriteLine("Square root of " + number + " is: " + squareRoot);
    }
    }

    OutPut

    Square root of 25 is: 5

  5. Pow(): Returns a specified number raised to the power of another number.
  6. Example

    using System;

    class Program
    {
    static void Main()
    {
    double baseNumber = 2;
    double exponent = 3;
    double result = Math.Pow(baseNumber, exponent);
    Console.WriteLine(baseNumber + " raised to the power of " + exponent + " is: " + result);
    }
    }

    OutPut

    2 raised to the power of 3 is: 8

  7. Round(): Rounds a decimal value to the nearest integer.

  8. using System;

    class Program
    {
    static void Main()
    {
    double number = 3.7;
    double roundedValue = Math.Round(number);
    Console.WriteLine("Rounded value of " + number + " is: " + roundedValue);
    }
    }

    OutPut

    Rounded value of 3.7 is: 4

    These are just a few examples of the mathematical functions provided by the System.Math class in C#. It offers many more functions for performing various mathematical calculations.



Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java