求教个问题使用C++编写一个小程序要求用Visual Studio可以运行

来源:百度知道 编辑:UC知道 时间:2024/06/03 00:49:54
要求取100个随机数 排序后 用户输入一个数 然后从抽到的随机数中查找 找到就输出found 找不到就输出not found查找过程循环 直到用户输出-1退出程序
100以内的可以重复的数字也是可以的 期待你们的消息
4楼的兄弟没有 输入-1退出的一步~5楼兄弟的正在试~再次谢谢
5楼兄弟可以直接修改成一个完整的可运行程序吗 要把随机出来的数显示出来也可能是修改的不好~目前正在想办法显示数字 正在调试ING~~

//试试这个行不行
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>

using namespace std ;

const int SIZE = 100 ;

inline void exchange( int& x , int& y ) {
int t = x ;
x = y ;
y = t ;
}

void printarray(int source[] , int size){
for ( int i = 0 ; i < size ; i++)
cout << setw(8) << source[i] ;
}

void creatarray(int source[] , int size){
//产生随机数
srand( static_cast<int>(time(0)) ) ;
for(int i = 0 ; i < size ; i ++ )
source[i] = rand() % size ;
}

void quicksort(int source[] , int start , int end )
{
//快速排序
if( start < end ){
int i = start ;
int j = end + 1 ;
while( i < j ) {
i++;
while( source[i] < source[start] )
++i ;
j--;
while( source[j] > source[start] )
--j ;