Q:

C# program to find the square root of a given number without using Math.Sqrt() method

belongs to collection: C# Basic Programs | basics

0

C# program to find the square root of a given number without using Math.Sqrt() method

All Answers

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

Program:

The source code to find the square root of a given number without using Math.Sqrt() is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to find the square root of a given 
//number without using Math.Sqrt() method.

using System;

class SquareRoot
{
    static int Main()
    {
        int     number  =   0;
        double  squareRoot=   0;
        
        Console.Write("Enter the value of number: ");
        number = Convert.ToInt32(Console.ReadLine());
        
        squareRoot = Math.Ceiling(Math.Pow(number, (double)1 / 2));
        Console.WriteLine("Square Root is : " + squareRoot);

        return 0;
    }
}

Output:

Enter the value of number: 36
Square Root is : 6
Press any key to continue . . .

Explanation:

Here, we created a class SquareRoot that contains the Main() method. The Main() method is an entry point for the program. Here we created two variables number and squareRoot that are initialized with 0. Then we read the value of the variable number. After that calculated the square root using Sqrt() method and then printed the square root on the console screen.

 

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

total answers (1)

C# Basic Programs | basics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to calculate the area of a Cone... >>
<< C# program to find the cube root of a given number...