4个回答
展开全部
Private Function zs(x As Integer) As Boolean '素数判断子过程
Dim d%
For d = 2 To Int(Sqr(x))
If x Mod d = 0 Then Exit For: zs = False
If d = Int(Sqr(x)) Then zs = True
Next
End Function
Private Sub Command1_Click()
Dim i%, j%, a!, c%, mSum%, mCunt%, mstr$, mArr
For i = 10 To 100
If zs(i) = True Then mstr = mstr & i & ",": j = j + i
Next
mArr = Split(Left(mstr, Len(mstr) - 1), ",")
a = j / (UBound(mArr) + 1)
For i = 0 To UBound(mArr)
If mArr(i) > a Then c = c + 1
Next
Print "10 ~ 100间质数: "
Print mstr
Print "总和: "; j
Print "总个数: ", UBound(mArr) + 1
Print "平均数: ", a
Print "大于平均数的个数: ", c
End Sub
Dim d%
For d = 2 To Int(Sqr(x))
If x Mod d = 0 Then Exit For: zs = False
If d = Int(Sqr(x)) Then zs = True
Next
End Function
Private Sub Command1_Click()
Dim i%, j%, a!, c%, mSum%, mCunt%, mstr$, mArr
For i = 10 To 100
If zs(i) = True Then mstr = mstr & i & ",": j = j + i
Next
mArr = Split(Left(mstr, Len(mstr) - 1), ",")
a = j / (UBound(mArr) + 1)
For i = 0 To UBound(mArr)
If mArr(i) > a Then c = c + 1
Next
Print "10 ~ 100间质数: "
Print mstr
Print "总和: "; j
Print "总个数: ", UBound(mArr) + 1
Print "平均数: ", a
Print "大于平均数的个数: ", c
End Sub
展开全部
Sub susu()
Dim su() As Integer, sum, i, j As Integer
Dim aver As Double
ReDim su(1 To 2)
su(1) = 2: su(2) = 3
For i = 4 To 100
issu = True
For j = 2 To i / 3 + 1
If i Mod j = 0 Then issu = False: Exit For
Next j
If issu Then ReDim Preserve su(1 To UBound(su) + 1): su(UBound(su)) = i: sum = sum + i
Next i
aver = sum / UBound(su)
Debug.Print "平均值:" & aver
Debug.Print "大于平均值的有:"
For i = 1 To UBound(su)
If su(i) > aver Then Debug.Print su(i)
Next
End Sub
Dim su() As Integer, sum, i, j As Integer
Dim aver As Double
ReDim su(1 To 2)
su(1) = 2: su(2) = 3
For i = 4 To 100
issu = True
For j = 2 To i / 3 + 1
If i Mod j = 0 Then issu = False: Exit For
Next j
If issu Then ReDim Preserve su(1 To UBound(su) + 1): su(UBound(su)) = i: sum = sum + i
Next i
aver = sum / UBound(su)
Debug.Print "平均值:" & aver
Debug.Print "大于平均值的有:"
For i = 1 To UBound(su)
If su(i) > aver Then Debug.Print su(i)
Next
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim sum As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim flag As Boolean
Dim a() As Integer
For i = 10 To 100
flag = False
For j = 2 To i / 2
If i Mod j = 0 Then
flag = True
Exit For
End If
Next j
If flag = False Then
k = k + 1
ReDim Preserve a(k) As Integer
a(k) = i
sum = sum + i
End If
Next i
Print "平均数:" & sum / k
j = 0
For i = 1 To k
If a(i) > sum / k Then j = j + 1
Next
Print "大于" & sum / k & "的有" & j & "个"
End Sub
Dim sum As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim flag As Boolean
Dim a() As Integer
For i = 10 To 100
flag = False
For j = 2 To i / 2
If i Mod j = 0 Then
flag = True
Exit For
End If
Next j
If flag = False Then
k = k + 1
ReDim Preserve a(k) As Integer
a(k) = i
sum = sum + i
End If
Next i
Print "平均数:" & sum / k
j = 0
For i = 1 To k
If a(i) > sum / k Then j = j + 1
Next
Print "大于" & sum / k & "的有" & j & "个"
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
下面这个是用筛选法实现的:
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(int ac, char** av) {
const MAX = 100;
bool sieve[MAX + 1];
fill(sieve, sieve + MAX + 1, true);
sieve[0] = false;
sieve[1] = false;
for (int n=2; n < sqrt((double)MAX + 1); n++) {
if (sieve[n]) {
for (int j=2*n; j < MAX + 1; j+=n)
sieve[j] = false;
}
}
for(int i = 2; i < MAX + 1; i++) {
if(sieve[i])
cout < < i < < endl;
}
}
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(int ac, char** av) {
const MAX = 100;
bool sieve[MAX + 1];
fill(sieve, sieve + MAX + 1, true);
sieve[0] = false;
sieve[1] = false;
for (int n=2; n < sqrt((double)MAX + 1); n++) {
if (sieve[n]) {
for (int j=2*n; j < MAX + 1; j+=n)
sieve[j] = false;
}
}
for(int i = 2; i < MAX + 1; i++) {
if(sieve[i])
cout < < i < < endl;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询