I modified C# "Math" Program according to suggestion but it is not working. Please correct it.
If one entered a number, squre root of that number should be the output. That means for example: If I entered 10 as a input, output should be 3.1622.
square root of 10 = 3.1622.
using System;
public class Math
{
public static void Main()
{
double sqrt, number;
string sNum;
Console.Write("Number = ");
sNum = Console.ReadLine();
number = Convert.ToDouble(sNum);
sqrt = SqrtRoot(number);
Console.WriteLine("Square Root of the number = {0}", sqrt);
}
public static double SqrtRoot(double num)
{
double sRoot;
sRoot = Math.Sqrt(num);
return sRoot;
}
}
Mike GoldRank #50 · 30.6K pointsPosted Mar 19, 2007, 2:07 PM EDT
Best,
Mike G.
using System; public class Math { public static void Main() { double sqrt, number; string sNum; Console.Write("Number = "); sNum = Console.ReadLine(); number = Convert.ToDouble(sNum); sqrt = SqrtRoot(number); Console.WriteLine("Square Root of the number = {0}", sqrt); Console.ReadLine(); } public static double SqrtRoot(double num) { return System.Math.Sqrt(num); } }Former memberPosted Mar 19, 2007, 2:38 PM EDT
not that Console.ReadLine(); but it is System.Math.Sqrt(num); correcting the program.