Csharp/C Sharp by API/System/Math
Содержание
Math.Abs
<source lang="csharp"> using System; public class MainClass {
public static void Main( ) { double epsilon = 1.0e-9; double guess = 11.0; double result = 0.0; double value = 2; result = ((value / guess) + guess) / 2; do { Console.WriteLine( "Guess Value = {0}", guess ); Console.WriteLine( "Result Value = {0}", result ); guess = result; result = ((value / guess) + guess) / 2; } while( Math.Abs(result - guess) > epsilon ); Console.WriteLine("The approx sqrt of {0} is {1}", value, result ); }
}
</source>
Math.Cos()
<source lang="csharp"> using System;
public class Trigonometry {
public static void Main() { Double theta; for(theta = 0.1; theta <= 1.0; theta = theta + 0.1) { Console.WriteLine("Sine of " + theta + " is " + Math.Sin(theta)); Console.WriteLine("Cosine of " + theta + " is " + Math.Cos(theta)); Console.WriteLine("Tangent of " + theta + " is " + Math.Tan(theta)); Console.WriteLine(); } }
}
</source>
Math.Min
<source lang="csharp"> using System; public class MainClass {
public static void Main() { int i = 5; Console.WriteLine("Math.Min(1,2) = {0}", Math.Min(i, 2.5F)); }
}
</source>
Math.PI
<source lang="csharp"> using System; using System.Data;
class Class1{
static void Main(string[] args){ Console.WriteLine(ConvertDegreesToRadians (180)); Console.WriteLine(ConvertDegreesToRadians (90)); Console.WriteLine(ConvertDegreesToRadians (30)); } public static double ConvertDegreesToRadians (double degrees) { double radians = (Math.PI / 180) * degrees; return (radians); }
}
</source>
Math.Round
<source lang="csharp"> using System; public class MainClass {
public static void Main() { Console.WriteLine(Math.Round(4.4)); Console.WriteLine(Math.Round(4.5)); Console.WriteLine(Math.Round(4.6)); Console.WriteLine(Math.Round(5.5)); Console.WriteLine(Math.Round(4.54, 1)); Console.WriteLine(Math.Round(4.55, 1)); Console.WriteLine(Math.Round(4.65, 1)); Console.WriteLine(Math.Round(4.56, 1)); }
}
</source>
Math.Sign
<source lang="csharp"> using System; public class MainClass {
public static void Main() { Console.WriteLine("Math.Sign(1) = {0}", Math.Sign(1)); Console.WriteLine("Math.Sign(-1) = {0}", Math.Sign(-1)); Console.WriteLine("Math.Sign(0) = {0}", Math.Sign(0)); }
}
</source>
Math.Sin()
<source lang="csharp"> using System;
public class Trigonometry {
public static void Main() { Double theta; for(theta = 0.1; theta <= 1.0; theta = theta + 0.1) { Console.WriteLine("Sine of " + theta + " is " + Math.Sin(theta)); Console.WriteLine("Cosine of " + theta + " is " + Math.Cos(theta)); Console.WriteLine("Tangent of " + theta + " is " + Math.Tan(theta)); Console.WriteLine(); } }
}
</source>
Math.Sqrt
<source lang="csharp">
using System; class MainClass {
public static void Main() { double s1 = 3.0; double s2 = 4.0; double hypot; hypot = Math.Sqrt(s1*s1 + s2*s2); Console.WriteLine("Hypotenuse is " + hypot); }
}
</source>
Math.Tan()
<source lang="csharp"> using System;
public class Trigonometry {
public static void Main() { Double theta; for(theta = 0.1; theta <= 1.0; theta = theta + 0.1) { Console.WriteLine("Sine of " + theta + " is " + Math.Sin(theta)); Console.WriteLine("Cosine of " + theta + " is " + Math.Cos(theta)); Console.WriteLine("Tangent of " + theta + " is " + Math.Tan(theta)); Console.WriteLine(); } }
}
</source>