- 论坛徽章:
- 0
|
在给定范围内随机产生规定个数的不同数字、看看谁写的最好。
应该给我满分吧!
#include <iostream>;
using namespace std;
void generate(int lower, int upper, int count)
{
int *x, i, total;
total=upper-lower+1;
x = new int[total];
for (i=0;i<total;i++) x=lower+i;
for (i=0;i<count;i++) {
swap(x,x[rand()%(total-i)+i]);
cout<<x<<" ";
}
cout<<endl;
delete [] x;
}
int main()
{
int l,u,c;
cout<<"Lower bound : ";
cin>;>;l;
cout<<"Upper bound : ";
cin>;>;u;
cout<<"How many : ";
cin>;>;c;
srand(time(NULL));
generate(l,u,c);
system(" AUSE" ;
exit(0);
} |
|