角度制下的反三角函数计算程序
VB.NET
①
Module ArcTrigono
Dim F, o, x, d, m, s As Primitive
Sub Main()
F(1) = "arcsin(x) = "
F(2) = "arcsec(x) = "
F(3) = "arccos(x) = "
F(4) = "arccsc(x) = "
F(5) = "arctan(x) = "
F(6) = "arccot(x) = "
Start:
TextWindow.Clear()
TextWindow.WriteLine("① arcsin(x)")
TextWindow.WriteLine("② arcsec(x)")
TextWindow.WriteLine("③ arccos(x)")
TextWindow.WriteLine("④ arccsc(x)")
TextWindow.WriteLine("⑤ arctan(x)")
TextWindow.WriteLine("⑥ arccot(x)")
TextWindow.Write("请选择:")
o = TextWindow.ReadNumber()
If o = 1 Then
Input()
If Microsoft.SmallBasic.Library.Math.Abs(x) > 1 Then
TextWindow.WriteLine("定义域错误!")
Else
d = Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcSin(x))
Output()
End If
ElseIf o = 2 Then
Input()
If Microsoft.SmallBasic.Library.Math.Abs(x) < 1 Then
TextWindow.WriteLine("定义域错误!")
Else
d = Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcCos(1 / x))
Output()
End If
ElseIf o = 3 Then
Input()
If Microsoft.SmallBasic.Library.Math.Abs(x) > 1 Then
TextWindow.WriteLine("定义域错误!")
Else
d = Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcCos(x))
Output()
End If
ElseIf o = 4 Then
Input()
If Microsoft.SmallBasic.Library.Math.Abs(x) < 1 Then
TextWindow.WriteLine("定义域错误!")
Else
d = Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcSin(1 / x))
Output()
End If
ElseIf o = 5 Then
Input()
d = Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcTan(x))
Output()
ElseIf o = 6 Then
Input()
d = 90 - Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcTan(x))
End If
Output()
Else
Goto Start
End If
End Sub
Sub Input()
TextWindow.Clear()
TextWindow.Write("x = ")
x = TextWindow.ReadNumber()
End Sub
Sub Output()
TextWindow.Write(F(o))
TextWindow.ForegroundColor = "Red"
TextWindow.Write(d + "度")
TextWindow.ForegroundColor = "Gray"
TextWindow.Write(" = ")
TextWindow.ForegroundColor = "Red"
If d < 0 Then
TextWindow.Write("-")
d = -d
End If
m = (d - Microsoft.SmallBasic.Library.Math.Floor(d)) * 60
d = Microsoft.SmallBasic.Library.Math.Floor(d)
s = (m - Microsoft.SmallBasic.Library.Math.Floor(m)) * 60
m = Microsoft.SmallBasic.Library.Math.Floor(m)
TextWindow.Write(d + "度")
TextWindow.ForegroundColor = "Yellow"
TextWindow.Write(m + "分")
TextWindow.ForegroundColor = "Green"
TextWindow.WriteLine(s + "秒")
TextWindow.ForegroundColor = "Gray"
End Sub
End Module
②
Module ArcTrigono
Dim F, o, x, d, m, s As Primitive
Sub Main()
F(1) = "arcsin(x) = "
F(2) = "arcsec(x) = "
F(3) = "arccos(x) = "
F(4) = "arccsc(x) = "
F(5) = "arctan(x) = "
F(6) = "arccot(x) = "
Start:
TextWindow.Clear()
TextWindow.WriteLine("① arcsin(x)")
TextWindow.WriteLine("② arcsec(x)")
TextWindow.WriteLine("③ arccos(x)")
TextWindow.WriteLine("④ arccsc(x)")
TextWindow.WriteLine("⑤ arctan(x)")
TextWindow.WriteLine("⑥ arccot(x)")
TextWindow.Write("请选择:")
o = TextWindow.ReadNumber()
If o = 1 Then
Input()
If (x < -1) Or (x > 1) Then
TextWindow.WriteLine("定义域错误!")
Else
d = Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcSin(x))
Output()
End If
ElseIf o = 2 Then
Input()
If (x > -1) And (x < 1) Then
TextWindow.WriteLine("定义域错误!")
Else
d = Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcCos(1 / x))
Output()
End If
ElseIf o = 3 Then
Input()
If (x < -1) Or (x > 1) Then
TextWindow.WriteLine("定义域错误!")
Else
d = Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcCos(x))
Output()
End If
ElseIf o = 4 Then
Input()
If (x > -1) And (x < 1) Then
TextWindow.WriteLine("定义域错误!")
Else
d = Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcSin(1 / x))
Output()
End If
ElseIf o = 5 Then
Input()
d = Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcTan(x))
Output()
ElseIf o = 6 Then
Input()
d = 90 - Microsoft.SmallBasic.Library.Math.GetDegrees(Microsoft.SmallBasic.Library.Math.ArcTan(x))
End If
Output()
Else
Goto Start
End If
End Sub
Sub Input()
TextWindow.Clear()
TextWindow.Write("x = ")
x = TextWindow.ReadNumber()
End Sub
Sub Output()
TextWindow.Write(F(o))
TextWindow.ForegroundColor = "Red"
TextWindow.Write(d)
TextWindow.Write("度")
TextWindow.ForegroundColor = "Gray"
TextWindow.Write(" = ")
TextWindow.ForegroundColor = "Red"
If d < 0 Then
TextWindow.Write("-")
d = -d
End If
m = (d - Microsoft.SmallBasic.Library.Math.Floor(d)) * 60
d = Microsoft.SmallBasic.Library.Math.Floor(d)
s = (m - Microsoft.SmallBasic.Library.Math.Floor(m)) * 60
m = Microsoft.SmallBasic.Library.Math.Floor(m)
TextWindow.Write(d)
TextWindow.Write("度")
TextWindow.ForegroundColor = "Yellow"
TextWindow.Write(m)
TextWindow.Write("分")
TextWindow.ForegroundColor = "Green"
TextWindow.Write(s)
TextWindow.WriteLine("秒")
TextWindow.ForegroundColor = "Gray"
End Sub
End Module
JScript.NET
①
import System;
var F=["定义域错误!","arcsin(x) = ","arcsec(x) = ","arccos(x) = ","arccsc(x) = ","arctan(x) = ","arccot(x) = "],o,x,d,m,s;
for(;;)
{
Console.Clear();
Console.Write("① arcsin(x)\n② arcsec(x)\n③ arccos(x)\n④ arccsc(x)\n⑤ arctan(x)\n⑥ arccot(x)\n请选择:");
o=Console.ReadLine();
if(o==1)
{
Input();
if(Math.abs(x)>1)
Console.WriteLine(F[0]);
else
{
d=Math.asin(x)/Math.PI*180;
Output();
}
break;
}
if(o==2)
{
Input();
if(Math.abs(x)<1)
Console.WriteLine(F[0]);
else
{
d=Math.acos(1/x)/Math.PI*180;
Output();
}
break;
}
if(o==3)
{
Input();
if(Math.abs(x)>1)
Console.WriteLine(F[0]);
else
{
d=Math.acos(x)/Math.PI*180;
Output();
}
break;
}
if(o==4)
{
Input();
if(Math.abs(x)<1)
Console.WriteLine(F[0]);
else
{
d=Math.asin(1/x)/Math.PI*180;
Output();
}
break;
}
if(o==5)
{
Input();
d=Math.atan(x)/Math.PI*180;
Output();
break;
}
if(o==6)
{
Input();
d=90-Math.atan(x)/Math.PI*180;
Output();
break;
}
}
function Input()
{
Console.Clear();
Console.Write("x = ");
x=Console.ReadLine();
}
function Output()
{
Console.Write(F[o]);
Console.ForegroundColor=12;
Console.Write(d+"度");
Console.ForegroundColor=7;
Console.Write(" = ");
Console.ForegroundColor=12;
if(d<0)
{
Console.Write("-");
d=-d;
}
m=(d-Math.floor(d))*60;
d=Math.floor(d);
s=(m-Math.floor(m))*60;
m=Math.floor(m);
Console.Write(d+"度");
Console.ForegroundColor=14;
Console.Write(m+"分");
Console.ForegroundColor=10;
Console.WriteLine(s+"秒");
Console.ForegroundColor=7;
}
②
import System;
var F=["定义域错误!","arcsin(x) = ","arcsec(x) = ","arccos(x) = ","arccsc(x) = ","arctan(x) = ","arccot(x) = "],o,x,d,m,s;
for(;;)
{
Console.Clear();
Console.Write("① arcsin(x)\n② arcsec(x)\n③ arccos(x)\n④ arccsc(x)\n⑤ arctan(x)\n⑥ arccot(x)\n请选择:");
o=Console.ReadLine();
if(o==1)
{
Input();
if(x<-1||x>1)
Console.WriteLine(F[0]);
else
{
d=Math.asin(x)/Math.PI*180;
Output();
}
break;
}
if(o==2)
{
Input();
if(x>-1&&x<1)
Console.WriteLine(F[0]);
else
{
d=Math.acos(1/x)/Math.PI*180;
Output();
}
break;
}
if(o==3)
{
Input();
if(x<-1||x>1)
Console.WriteLine(F[0]);
else
{
d=Math.acos(x)/Math.PI*180;
Output();
}
break;
}
if(o==4)
{
Input();
if(x>-1&&x<1)
Console.WriteLine(F[0]);
else
{
d=Math.asin(1/x)/Math.PI*180;
Output();
}
break;
}
if(o==5)
{
Input();
d=Math.atan(x)/Math.PI*180;
Output();
break;
}
if(o==6)
{
Input();
d=90-Math.atan(x)/Math.PI*180;
Output();
break;
}
}
function Input()
{
Console.Clear();
Console.Write("x = ");
x=Console.ReadLine();
}
function Output()
{
Console.Write(F[o]);
Console.ForegroundColor=12;
Console.Write(d);Console.Write("度");
Console.ForegroundColor=7;
Console.Write(" = ");
Console.ForegroundColor=12;
if(d<0)
{
Console.Write("-");
d=-d;
}
m=(d-Math.floor(d))*60;
d=Math.floor(d);
s=(m-Math.floor(m))*60;
m=Math.floor(m);
Console.Write(d);Console.Write("度");
Console.ForegroundColor=14;
Console.Write(m);Console.Write("分");
Console.ForegroundColor=10;
Console.Write(s);Console.WriteLine("秒");
Console.ForegroundColor=7;
}
Forse altri canterà con miglior plettro.