top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

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

0 votes
60 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 Google+ Share Button LinkedIn Share Button Multiple Social 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 4 days ago by Rushabh Verma R.
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...