用VB编写程序,找出所有小于或等于100的自然数对。
public class A {
/**
* @param args
*/
public static void main(String[] args) {
for(int i = 50;i < 100; i++){
boolean isPrime = true;
for(int j = 2; j <= 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,
Private Sub Form_Activate()
Dim i%, j%, x%, y%
For i = 1 To 100
For j = 1 To i
x = i + j
y = i - j
If y > 0 Then
If Sqr(x) = Int(Sqr(x)) And Sqr(y) = Int(Sqr(y)) Then
Print i, j
End If
End If
Next j
Next i
End Sub
Private Sub Command1_Click()
For i = 1 To 99
For j = i + 1 To 100
t1 = Round(Sqr(i + j))
t2 = Round(Sqr(j - i))
If t1 * t1 = i + j And t2 * t2 = j - i Then Print "(" & i; ","; j; ")": n = n + 1
Next
Next
Print "N="; n
End Sub
把Text1文本框控件的MultyLine属性设置为True,再把
If t1 * t1 = i + j And t2 * t2 = j - i Then Print "(" & i; ","; j; ")": n = n + 1
改为:
If t1 * t1 = i + j And t2 * t2 = j - i Then
Text1 = Text1 & "(" & i & "," & j & ")" & VbCrlf
n = n + 1
End If
0也是自然数
Private Sub Command1_Click()
Dim i As Integer, j As Integer
For i = 0 To 100
For j = i + 1 To 100
If Int(Sqr(i + j)) ^ 2 = i + j And _
Int(Sqr(Abs(i - j))) ^ 2 = Abs(i - j) Then
Text1.Text = Text1.Text & i & " " & j & vbCrLf
End If
Next
Next
End Sub
Private Sub Form_Load()
'Text1的属性MultiLine设置为True
'Text1的属性ScrollBars设置为 2
Text1.Text = ""
End Sub
vb程序设计:根据给定的查找值,在数组中找出与之相同的元素
Dim a(1 To 10, 1 To 10) As Long Private Sub Command1_Click()Dim i As Integer Dim b As Long Dim s As String Dim f As Boolean b = Val(InputBox("请输入要查找的数!"))If b >= 10 And b <= 100 Then For i = 1 To UBound(a, 1)For j = 1 To UBound(a, 2)...
求VB高手:编写程序,找出10000~99999的所有回文数!
Private Sub Command1_Click()Dim I As Long, J As Long Dim X1 As Long, X2 As Long Dim str As String Dim Flag As Boolean str = "从 10000 到 99999 之间的回文数有:" & vbCrLf For I = 10000 To 99999 Flag = False For J = 1 To Len(CStr(I))If Mid(CStr(I), J, ...
用VB,编一个程序,从键盘输入两个数,找出较大的一个数,并打印出来
private sub from_load()dim a%,b a=msgbox("请输入第一个数:")b=msgbox("请输入第二个数:")if a>b then b=a print "较大的数是:" & b end sub
VB的程序设计 关于找出1到100之间的素数
Private Sub Command1_Click()Dim i As Long, j As Long, s As String For i = 2 To 100 For j = 2 To i - 1 If i \\ j = i \/ j Then Exit For Next If j = i Then s = s & i & " "Next MsgBox "1到100之间的素数:" & s End Sub ...
请用vb编写一个找出10000以内的亲密数对的小程序
需要两个函数,一个因子和计算,一个因子和输出。程序窗体放置一个文本框,设置其MultiLine为True。源程序如下:Option Explicit Dim I As Long, J As Long, X As Long Private Sub Form_Load()Me.Show For I = 1 To 10000 DoEvents X = Yzh(I)If X <= 10000 And I < X Then If Yzh...
vb编程问题 编写找出所有升序数的程序,所谓升序数就是个位大于十位,十...
只找三位数吗?在窗体上增加一个textBox1,然后指定多行显示 (当然也可以使用别的方法输出结果)增加一个子程序,程序代码如下 dim num as long dim a,b,c as interger for num=100 to 999 a=num mod 10 b=(num\/10) mod 10 c=num\/100 if a>b and b>c then textBox1.text=textBox1....
编写程序,找出某个正整数所有不同因子及因子个数 VB
Private Sub Command1_Click()x = CInt(InputBox("X="))Print x; " 的因子有:"n = 1 For i = 2 To x \\ 2 If x Mod i = 0 Then Print i;n = n + 1 End If Next i Print x Print "共 "; n; " 个因子"End Sub ...
vb编写程序,求出所有小于或等于100的自然数对。 请高手帮忙!!_百度知...
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer Dim j As Integer Dim A As Integer Dim B As Integer For i = 1 To 100 For j = i + 1 To 100 A = j - i B = j + i ...
找出100到300的所有素数用VB 编写程序怎么写
Private Sub Command1_Click()For i = 101 To 299 Step 2 For j = 2 To i - 1 If i Mod j = 0 Then Exit For Next If j = i Then Print i;k = k + 1 If k Mod 10 = 0 Then Print End If Next End Sub
用VB编写程序找出M×N矩阵的“鞍点
Dim c(2, 2) As Integer Private Sub Command1_Click()MsgBox star(2, 2)End Sub Private Sub Form_Load()c(0, 0) = 1 c(0, 1) = 2 c(0, 2) = 3 c(1, 0) = 4 c(1, 1) = 5 c(1, 2) = 6 c(2, 0) = 7 c(2, 1) = 8 c(2, 2) = 9 End Sub Private...
冯娜贝友: 下面是使用asp代码(VB)写的自然数对 <% for i=1 to 500 step 1 for j=(i+1) to 500 step 1 if sqr(i+j)=int(sqr(i+j)) and sqr(j-i)=int(sqr(j-i)) then response.Write(i&","&j&"是自然数对"&"<br>") end if next next %>
日喀则地区19717616252: vb编写查找小于某个数的所有素数 - ?
冯娜贝友: 给你一个代码,运行20000以内的只需要2秒钟. Private Sub Command1_Click() Dim x As String, i As Integer, B() As Integer, J As Integer, N As Integer, R As String Text1.Text = "" x = InputBox("你想求多少以内的质数?", "输入数据",...
日喀则地区19717616252: 用vb程序找出某一文本框中小于或者大于某一个数的程序怎么写? - ?
冯娜贝友: 比如: 如果文本框Text1里的数值大于或者小于100,就把这个100显示在文本框Text2里,这样可以吗? 我把问题简化一下(当然不简化也可以做),小于或者大于,其实就是不等于. If Val(Text1.text) <> 100 ThenText2.txet = Text1.text End If
日喀则地区19717616252: vb编程,有一串30位的数字,统计出其中有多少个数大于等于5,多少个小于等于4,大于5的数字之和为多少,小于等于4的数字之和为多少??
冯娜贝友: Private Sub Command1_Click() Dim r As String Do While Len(r) <> 30 '字符串的长度 r = InputBox("请输入三十个数字:") '输入任意一个30位的数 Loop For i = 1 To Len(r) b = Val(Mid(r, i, 1)) '取出字符串r中从第i个开始取一个字符 If b >= 5 ...
日喀则地区19717616252: [VB解题]编写程序找出所有小于1000的完数 - ?
冯娜贝友: Private Sub Command1_Click() Dim N As Long For N = 2 To 1000 If YinZi(N) = N Then List1.AddItem N End If Next N End Sub Private Function YinZi(ByVal N As Long) As Long Dim i As Long, S As Long YinZi = 1 For i = 2 To N / 2 If N Mod i = 0 Then YinZi = YinZi + i Next i End Function
日喀则地区19717616252: 急求!!『用VB编写随机生成100个两位整数的程序,并统计出其中小于等于40、大于40、小于等于70和大于70的数据个数.』?
冯娜贝友: dim i as integer ,n as integerdim n40 as integer ,n4070 as integer ,n70 as integerfor i = 1 to 100 n = int(rnd()*90 +10) if n<=40 thenn40=n40+1 elseif n<=70 thenn4070=n4070+1 elsen70=n70+1 endifnextmsgbox n40msgbox n4070 msgbox n70
日喀则地区19717616252: vb查询时要查大于,小于,或等于某个时间的数据,该怎么写代码 - ?
冯娜贝友: 1、SQL="select * from 要查询的数据表名 where 数据表中的时间字段> cdate('" & SHJ & "')" 其中SHJ变量的格式必须是:"XXXX-XX-XX YY:YY:YY" 2、SQL="select * from 要查询的数据表名 where 数据表中的时间字段< cdate('" & SHJ ...
日喀则地区19717616252: vb如何编写一个这样的程序:用户输入一个数后,若这个数小于1,程序显示“小于1”;若这个数大于1,程序把从1到这个数的所有整数加起来并显示这些数的和;用户输入“#”时程序结束运行 - ?
冯娜贝友: Private Sub Command1_Click() a = InputBox("请输入一个整数", "输入") If Val(a) < 1 Then Print "小于1" If Val(a) > 1 Then For i = 1 To Val(a) s = s + i Next i Print s End If If a = "#" Then End End Sub
日喀则地区19717616252: 用VB写一个从10个数中找出最小值的程序(不要用数组) - ?
冯娜贝友: Private Sub Command1_Click() Dim Min As Integer, I As Integer, T As Integer Min = Val(InputBox("请输入:")) Print Min; For I = 2 To 10 T = Val(InputBox("请输入:")) Print T; If T < Min Then Min = T Next Print Print "最小:" & Min End Sub
日喀则地区19717616252: vb 编写一个程序,输入任意10个数字,从中找出最大和最小的数,并给出最大和最小的书在数组中位置 - ?
冯娜贝友: Option Base 1 Private Sub Command1_Click() Dim s(10) As Integer Dim Max As Integer, maxi As Integer, Min As Integer, mini As Integer s(1) = Val(InputBox("请输入第1个元素")) Min = s(1): mini = 1: Max = s(1): maxi = 1 For i = 2 To 10 s(i) = ...