C# Function which returns the absolute value of an integer that is passed as a parameter.

/* C# Function which returns the absolute value of an integer that is passed as a parameter. */
using System;
public class Demo
{
    public static int abso(float a)
    {
        int c = 0;
        c = (int)(Math.Abs(a));
        return c;
    }

    public static void Main(string[] args)
    {
        int ab = 0;
        float b;
        Console.WriteLine("Enter a digit : ");
        b = float.Parse(Console.ReadLine());
        ab = abso(b);
        Console.WriteLine("Absolute value of entered digit is  : {0}", ab);
        Console.ReadLine();
    }
}

Output :
Enter a digit : 5.6
Absolute value of entered digit is : 5



Leave a comment