角度制下的锐角三角函数计算程序
Perl
①
use Win32::Console::ANSI;print "\33[2J\33[H";print "度:";chomp($d=<STDIN>);if($d<=0||$d>=90){print "输入错误:非锐角!\12";}else {print "分:";chomp($_=<STDIN>);$d+=$_/60;if($d<=0||$d>=90){print "输入错误:非锐角!\12";}else {print "秒:";chomp($_=<STDIN>);$d+=$_/60/60;if($d<=0||$d>=90){print "输入错误:非锐角!\12";}else {$r=.31415926535897932384626433832795/18*$d;$x=cos($r);$y=sin($r);print "\33[2J\33[H";print "\33[91msin (";print $d;print "°) = ";print $y;print "\12";print "\33[92msec (";print $d;print "°) = ";print(1/$x);print "\12";print "\33[93mcos (";print $d;print "°) = ";print $x;print "\12";print "\33[94mcsc (";print $d;print "°) = ";print(1/$y);print "\12";print "\33[95mtan (";print $d;print "°) = ";print($y/$x);print "\12";print "\33[96mcot (";print $d;print "°) = ";print($x/$y);print "\12";print "\33[0m";}}}
②
use Win32::Console::ANSI;use Math::Trig;print "\33[2J\33[H","度:";chomp($d=<STDIN>);if($d<=0||$d>=90){print "输入错误:非锐角!\12";}else {print "分:";chomp($_=<STDIN>);$d+=$_/60;if($d<=0||$d>=90){print "输入错误:非锐角!\12";}else {print "秒:";chomp($_=<STDIN>);$d+=$_/3600;if($d<=0||$d>=90){print "输入错误:非锐角!\12";}else {$r=deg2rad($d);print "\33[2J\33[H","\33[91msin (",$d,"°) = ",sin($r),"\12","\33[92msec (",$d,"°) = ",sec($r),"\12","\33[93mcos (",$d,"°) = ",cos($r),"\12","\33[94mcsc (",$d,"°) = ",csc($r),"\12","\33[95mtan (",$d,"°) = ",tan($r),"\12","\33[96mcot (",$d,"°) = ",cot($r),"\12","\33[0m";}}}
VB.NET
①
Module TrigonometryDim d, r, x, y As PrimitiveSub Main()TextWindow.Clear()TextWindow.Write("度:")d = TextWindow.ReadNumber()If (d <= 0) Or (d >= 90) ThenTextWindow.WriteLine("输入错误:非锐角!")ElseTextWindow.Write("分:")d = d + (TextWindow.ReadNumber() / 60)If (d <= 0) Or (d >= 90) ThenTextWindow.WriteLine("输入错误:非锐角!")ElseTextWindow.Write("秒:")d = d + (TextWindow.ReadNumber() / 60 / 60)If (d <= 0) Or (d >= 90) ThenTextWindow.WriteLine("输入错误:非锐角!")Elser = .31415926535897932384626433832795 / 18 * dx = Microsoft.SmallBasic.Library.Math.Cos(r)y = Microsoft.SmallBasic.Library.Math.Sin(r)TextWindow.Clear()TextWindow.ForegroundColor = "Red"TextWindow.WriteLine("sin (" + d + "°) = " + y)TextWindow.ForegroundColor = "Green"TextWindow.WriteLine("sec (" + d + "°) = " + (1 / x))TextWindow.ForegroundColor = "Yellow"TextWindow.WriteLine("cos (" + d + "°) = " + x)TextWindow.ForegroundColor = "Blue"TextWindow.WriteLine("csc (" + d + "°) = " + (1 / y))TextWindow.ForegroundColor = "Magenta"TextWindow.WriteLine("tan (" + d + "°) = " + (y / x))TextWindow.ForegroundColor = "Cyan"TextWindow.WriteLine("cot (" + d + "°) = " + (x / y))TextWindow.ForegroundColor = "Gray"End IfEnd IfEnd IfEnd SubEnd Module
②
Module TrigonometryDim d, r, x, y, z As PrimitiveSub Main()TextWindow.Clear()TextWindow.Write("度:")d = TextWindow.ReadNumber()If (d <= 0) Or (d >= 90) ThenTextWindow.WriteLine("输入错误:非锐角!")ElseTextWindow.Write("分:")d = d + (TextWindow.ReadNumber() / 60)If (d <= 0) Or (d >= 90) ThenTextWindow.WriteLine("输入错误:非锐角!")ElseTextWindow.Write("秒:")d = d + (TextWindow.ReadNumber() / 3600)If (d <= 0) Or (d >= 90) ThenTextWindow.WriteLine("输入错误:非锐角!")Elser = Microsoft.SmallBasic.Library.Math.GetRadians(d)x = Microsoft.SmallBasic.Library.Math.Cos(r)y = Microsoft.SmallBasic.Library.Math.Sin(r)z = Microsoft.SmallBasic.Library.Math.Tan(r)TextWindow.Clear()TextWindow.ForegroundColor = "Red"TextWindow.Write("sin (")TextWindow.Write(d)TextWindow.Write("°) = ")TextWindow.WriteLine(y)TextWindow.ForegroundColor = "Green"TextWindow.Write("sec (")TextWindow.Write(d)TextWindow.Write("°) = ")TextWindow.WriteLine(1 / x)TextWindow.ForegroundColor = "Yellow"TextWindow.Write("cos (")TextWindow.Write(d)TextWindow.Write("°) = ")TextWindow.WriteLine(x)TextWindow.ForegroundColor = "Blue"TextWindow.Write("csc (")TextWindow.Write(d)TextWindow.Write("°) = ")TextWindow.WriteLine(1 / y)TextWindow.ForegroundColor = "Magenta"TextWindow.Write("tan (")TextWindow.Write(d)TextWindow.Write("°) = ")TextWindow.WriteLine(z)TextWindow.ForegroundColor = "Cyan"TextWindow.Write("cot (")TextWindow.Write(d)TextWindow.Write("°) = ")TextWindow.WriteLine(1 / z)TextWindow.ForegroundColor = "Gray"End IfEnd IfEnd IfEnd SubEnd Module
Forse altri canterà con miglior plettro.
