1、随机产生10个10-99范围内的整数,分别用选择和冒泡法将数据按从大到小递减的顺序排列,并显示排序结果

如题所述

Private Sub Form_click()
Dim A(1 To 10)
Randomize
For I = 1 To 10
A(I) = Int(Rnd * 90) + 10
Next I
For I = 1 To 9 '选择法
p = I
For J = I + 1 To 10
If A(J) < A(I) Then
p = J
End If
Next J
tem = A(I)
A(I) = A(p)
A(p) = tem
Next I
For I = 1 To 10
A(I) = A(11 - I)
Next I

For I = 1 To 9 '冒泡法
For J = 1 To 10 - I
If A(J) > A(J + 1) Then
tem = A(I)
A(I) = A(p)
A(p) = tem
End If
Next J
Next I
For I = 1 To 10
A(I) = A(11 - I)
Next I

End Sub
这就好了 你试试哦
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-04-12
在窗体上添加一个按钮Command1 ,然后把下面代码复制到窗体代码中

Private Const N = 100 'N个,可以修改N等于多少
Private Sub Command1_Click()
Dim i As Integer
Dim a(1 To N) As Integer
For i = 1 To N
Randomize
a(i) = Int(Rnd * 90 + 10)
Next
Call MaoPaoSort(a)
Cls
For i = 1 To N
If i Mod 10 = 1 Then Print '每行打印10个数据
Print a(i);
Next
End Sub
'冒泡排序函数
Sub MaoPaoSort(a() As Integer)
Dim i As Integer
Dim j As Integer
Dim temp As Integer
For i = LBound(a()) To UBound(a()) - 1
For j = LBound(a()) To UBound(a()) - 1
If a(j) > a(j + 1) Then
temp = a(j)
a(j) = a(j + 1)
a(j + 1) = temp
End If
Next
Next
End Sub
第2个回答  2011-10-24
这是用Java写的:

import java.util.Scanner;

public class randomSortTest {
int[] ran = new int[99];

public static void main(String[] args) {
randomSortTest rs = new randomSortTest();
rs.randomNumber(10, 99, 99);
System.out.println("是否进行排序? <Y/N>");
String YND = "";
YND = new Scanner(System.in).next();
if (YND.equalsIgnoreCase("Y")) {
do {
System.out.println("升序/降序? <R/D>");
YND = new Scanner(System.in).next();
if (YND.equalsIgnoreCase("R") || YND.equalsIgnoreCase("D")) {
break;
}
} while (true);
if (YND.equalsIgnoreCase("R")) {
rs.ranSortRise();
System.out.println("升序后结果:");
} else if (YND.equalsIgnoreCase("D")) {
rs.ranSortDrop();
System.out.println("降序后结果:");
}
} else {
System.out.println("未结果:");
}
for (int x : rs.ran) {
System.out.println(x);
}
}

public void randomNumber(int rangeStat, int rangeEnd, int number) {
int x = 0;
for (int i = 0; i < number;) {
x = (int) (Math.random() * (rangeEnd + 1));
if (x < rangeStat) {
continue;
}
ran[i] = x;
i++;
}
}

public void ranSortRise() {
int ranSize = ran.length;
for (int k = 0, conversion = 0; k < ranSize; k++) {// 升序
for (int j = 0; j < (ranSize - 1); j++) {
if (ran[j] > ran[j + 1]) {
conversion = ran[j];
ran[j] = ran[j + 1];
ran[j + 1] = conversion;
}
}
}
}

public void ranSortDrop() {
int ranSize = ran.length;
for (int k = 0, conversion = 0; k < ranSize; k++) {// 降序
for (int j = 0; j < (ranSize - 1); j++) {
if (ran[j] < ran[j + 1]) {
conversion = ran[j];
ran[j] = ran[j + 1];
ran[j + 1] = conversion;
}
}
}

}
}

(1)编写程序,利用随机函数产生并输出10个10~99之间的随机整数,再按升...
Private Sub Command1_Click()Cls Dim a(10) As Integer Dim b As Integer For i = 1 To 10 a(i) = Int(Rnd * 90 + 10)For j = 1 To i If a(j) > a(i) Then b = a(j)a(j) = a(i)a(i) = b End If Next j Print a(i)Next i End Sub ...

vb程序中 输出10个[10,99]范围内随机整数用“生成”按钮, 用“统计...
'生成是个随机数 private sub sc_click()'下面这一句可以得到不同的随机数 randomize '不用这一句也可以,不影响效果 for i=1 to 10 a(i)=int(rnd*90+10)next i end sub '统计随机数奇偶数个数 private sub tj_click()dim j as integer,o as integer for i=1 to 10 if a(i) mod...

用C语言,随机输入10个整数,用冒泡排序法对这些整数进行从小到大排序...
int a[10];int b[10]={9,10,11,12,1,2,3,4,0,1};int c[10]={1,2,3,4,13,14,15,16,2,3};int i;printf("请输入待排序的10个数:");for(i=0;i<10;i++){ scanf("%d",&a[i]);} fun(a);printf("\\n排序后的数列如下:\\n");for(i=0;i<10;i++){ printf("...

vb编写一个程序,利用随机函数Rnd生成10个10-99之间的整数,并计算其中素...
n= [ 10+int(90*rnd) ]st = [ st + " " + n ]forj=2 to [ n ][ n1=n1+1 ][ exit for ]text1.text=[ st ]text2.text= [ n-n1 ]

VB利用随机函数Rnd生成10个10-99的整数,并计算其中的素数个数。(求大神...
1、首先,我们给主函数先定一个函数。2、然后我们编写For循环语句。3、然后我们编写输出语句及范围。4、然后我们开始运行测试。5、这句警告没关系,如果不想看到可以添加调用数学函数。6、这时我们便可以看到效果了。

...随机产生20个10~99之间的整数,要求: 1) 用冒泡法排序(降序) 2...
x=val(inputbox("请输入一个整数"))redim a%(x)for i= 1 to x a(i)=int (rnd*90+10)next i for i= 1 to x for j=i+1 to x-i if a(j)

SQL 产生10个20—99之间的随机整数
其实这个问题很简单了 你都知道的,rand()函数产生的是0到1之间的小树 那么用rand()*100 就是0到100的整数(可以用直接截取前面两位也就是整数部分,然后过滤出大于50的)

输入10个整数,(范围1~99之间)请打印出最大值
很简单

SQL 产生10个20—99之间的随机整数
SELECT FLOOR(RAND()* 79 + 20)用上面的sql执行,可以得出20到99之间的一个随机整数,然后你可以用循环或者重新使用10次得出10个随机数

...题:随机产生m个【10,99】之间互不相同的正整数,将它们从小到大排列后...
void main(){ bool num[length_set],num_default;int m,i,j,r;\/\/获取m数\/\/ printf("随机产生m个[10,99]之间互不相同的正整数\\nm=",&m);scanf("%d",&m);if(m<0){ m = 0;} else if(m>length_set){ m = length_set;} printf("可接受的m=%d\\n",m);\/\/快速初始化num...

相似回答