Q:

C# program to demonstrate the use of Abs() method of Math class

belongs to collection: C# Math Class Programs

0

C# program to demonstrate the use of Abs() method of Math class

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to demonstrate the use of Abs() method of Math class is given below. The given program is compiled and executed successfully.

using System;
using System.IO;

class Sample
{
    //Entry point of Program
    static public void Main()
    {
        double[] doubles = { Double.MaxValue,Double.MinValue, 157.37, 120.00, -5.96 };
        decimal[] decimals = { Decimal.MaxValue,Decimal.MinValue, 157.37M, 120.00M, -5.96M };

        int[] integers = { Int32.MaxValue,Int32.MinValue, 157, 120, -5 };

        Console.WriteLine("Double Values:");
        foreach (double VAL in doubles)
            Console.WriteLine("\tMath.Abs({0}) : {1}", VAL, Math.Abs(VAL));

        Console.WriteLine("\nDecimal Values:");
        foreach (decimal VAL in decimals)
            Console.WriteLine("\tMath.Abs({0}) : {1}", VAL, Math.Abs(VAL));

        Console.WriteLine("\nInteger Values:");
        foreach (decimal VAL in integers)
            Console.WriteLine("\tMath.Abs({0}) : {1}", VAL, Math.Abs(VAL));   
    }
}

Output:

Double Values:
        Math.Abs(1.79769313486232E+308) : 1.79769313486232E+308
        Math.Abs(-1.79769313486232E+308) : 1.79769313486232E+308
        Math.Abs(157.37) : 157.37
        Math.Abs(120) : 120
        Math.Abs(-5.96) : 5.96

Decimal Values:
        Math.Abs(79228162514264337593543950335) : 79228162514264337593543950335
        Math.Abs(-79228162514264337593543950335) : 79228162514264337593543950335

        Math.Abs(157.37) : 157.37
        Math.Abs(120.00) : 120.00
        Math.Abs(-5.96) : 5.96

Integer Values:
        Math.Abs(2147483647) : 2147483647
        Math.Abs(-2147483648) : 2147483648
        Math.Abs(157) : 157
        Math.Abs(120) : 120
        Math.Abs(-5) : 5
Press any key to continue . . .

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# program to demonstrate the use of Round() metho... >>