top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to find the absolute value of a number in C# ?

0 votes
378 views
How to find the absolute value of a number in C# ?
posted May 20, 2016 by Jayshree

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AbundantcodeConsoleApp
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            // How to find the absolute value of a number in C# ?
            int input = -1996;
            if (input < 0)
            {
                input = input * -1;
            }

            Console.WriteLine("Absolute value : " + input);
            Console.ReadLine();
        }
    }

}
answer May 20, 2016 by Shivaranjini
0 votes
using System;

namespace ConsoleApp16
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the number");
            int i = int.Parse(Console.ReadLine());
            if(i<0)
            {
                i = i * (-1);

            }
            else if(i==0)
            {
                i = 0;
            }
            else
            {
                i = i;
            }
            Console.WriteLine("absolute number is {0}", i);
            Console.ReadLine();
        }
    }
}
answer May 15, 2019 by Rushabh Verma R.
...