VB数组排序的问题
Private Sub Command1_Click()Dim a(9) As Integer, i, j, t As Integer
For i = 0 To 9
a(i) = InputBox("请输入数字!")
Print a(i);
Next i
For i = 1 To 8
For j = 9 To i
If a(j) < a(j - 1) Then
t = a(j): a(j) = a(j - 1): a(j - 1) = t
End If
Next j
Next i
Print "after compositor the array is :"
For i = 0 To 9
Print a(i);
Next i
End Sub
经过循环后相当于没循环,直接就把输入的数组输出了!怎么解决这个问题?调用函数吗?请高手指导。
用C语言编写上述程序如下:
#include "stdio.h"
main()
{int a[10],i,j,t;
printf("\nplease input array!\n");
for(i=0;i<10;i++)
scanf("%d",&a[i]) ;
for(i=0;i<9;i++)
{
for(j=10;j>i;j--)
{
if(a[j]<a[j-1])
{t=a[j];a[j]=a[j-1];a[j-1]=t;}
}
}
printf("\nafter compositor the array is:\n") ;
for(i=0;i<10;i++)
printf("%d ",a[i]);
}