c++ 关于随机数 然后排序的问题
#include "stdafx.h"
#include<iostream>
#include<ctime>
using namespace std;
void useRand(int a[],int size);
void afterSorting(int a[],int size);
int main()
{
int a[10];
useRand(a,10);
afterSorting(a,10);
return 0;
}
void useRand(int a[],int size)
{
srand((unsigned)time(NULL));
cout << "the rand number is:" <<endl;
for(int i=0;i<=9;i++)
{
a[i]=rand()%10+1;
cout << a[i] << endl;
}
}
void afterSorting(int a[],int size)
{
cout << "after sorting:" << endl;
for(int i=0;i<10;i++)
{
int temp;
for(int j=9;j>i;j--)
{
if (a[j] > a[j-1])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
cout << a[i] << endl;
}
}
以上是我写的,最后结果有时对有时错,我在纸上也画了半天,感觉不出哪里有问题了。。请教帮看看~~
[解决办法]
排序算法错了