Sqrt giving incorrect values

Viewed 22

This is my code, my console give me incorrect result I'm new to this programming language and I don't understand why my code doesn't work the way I want it to. If I enter 81, then I expect to see 9, but there are completely different values

using System;

namespace Lab2
{
    internal class Program
    {
        static void Main()
        {
            Console.WriteLine("Введите X и нажмите Enter");
            int x = Console.Read();
            double resultat;
            if (x > 0)
            {
                resultat = Math.Sqrt(x);
                Console.Write(resultat);
            }
            else if (x == 0)
            {
                resultat = 21;
                Console.Write(resultat);
            }
            else if (x < 0)
            {
                resultat = Math.Sqrt(1+(Math.Pow(x,2)));
                Console.Write(resultat);
            }
        }
    }
}
0 Answers
Related