用程序找出50以内构成直角三角形

用程序找出50以内构成直角三角形,第1张

1、以下程序是找出50以内所有能构成直角三蚂返角形的整数组.请完成程序斗物腔.

Private Sub Command1_Click()

For a=1 To 50

For b=a To 50

c=Sqr(a^2+b^2)

If ____ And c=Int(c) Then Print abc

Next b

Next a

End Sub

答空衫案 c

Rem 创建窗体,在上面放Command1、Command2、Command3三个按钮,一个Text1文本闷梁框,文本框的MultiLine属性设置为True,ScrollBars设置为2

Rem 0也是平方数哈

Private Sub Command1_Click()

Dim i%, j%, k%, flag As Boolean

Text1.Text = ""

k = 0

For i = 0 To 50

flag = False

For j = 0 To i

If IsPf(j) And IsPf(i - j) Then flag = True: Exit For

Next

If flag = False Then

k = k + 1

Text1.Text = Text1.Text &" " &i

If k Mod 5 = 0 Then Text1.Text = Text1.Text &vbCrLf

End If

Next

Command2.Enabled = True

End Sub

Private Sub Command2_Click()

Text1.Text = ""

Command3.Enabled = True

End Sub

Private Sub Command3_Click()

End

End Sub

Private Sub Form_Load()

Command1.Caption = "开始"蚂腊运

Command2.Caption = "清局友除"

Command3.Caption = "退出"

Command2.Enabled = False

Command3.Enabled = False

End Sub

Private Function IsPf(ByVal n As Integer) As Boolean

If n = Int(Sqr(n)) * Int(Sqr(n)) Then IsPf = True Else IsPf = False

End Function

public class A {

/**

* @param args

*/

public static void main(String[] args) {

for(int i = 50i <100i++){

boolean isPrime = true

for(int j = 2j <= Math.sqrt(i)j++){

if(i % j == 0){

isPrime = false

break

}

}

if(isPrime){

System.out.print(i + "虚裤腔纯瞎, "差衫)

}

}

}

}

-----------testing

53, 59, 61, 67, 71, 73, 79, 83, 89, 97,


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8254426.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-14
下一篇 2023-04-14

发表评论

登录后才能评论

评论列表(0条)

保存