#include<iostream>
#include<ctime>
#include<set>
GetRandNumber(int *a,int n,int s,int e)
{
int i,j;
std::set<int> m;
std::set<int>::iterator setpos;
srand(time(NULL));
while(m.size()<n)
{
j=rand()%(e-s)+s;
m.insert(j);
}
i=0;
for(setpos=m.begin();setpos!=m.end();setpos++)
a[i++]=*setpos;
}
void show(int a[],int n)
{
using namespace std;
double sum=a[0];
double ave=0;
for(int i=0;i<n;i++)
{
cout<<a[i]<<' ';
sum+=a[i];
}
cout<<endl;
ave=sum/n;
cout<<"★★平均数是★★:"<<ave<<endl;
cout<<"★★★随机数的和是★★★:"<<sum<<endl;
//putchar('n');
}
int main()
{
using namespace std;
system ("color e");
cout<<" ★月护王★"<<endl<<" QQ:584033744"<<endl;
const int NMAX=20;
const int NUMBERSTART=1;
const int NUMBEREND=100;
cout<<"★★★★★生成"<<NMAX<<"个"<<"从"<<NUMBERSTART<<"到"<<NUMBEREND<<"的随机数★★★★★:\n";
int a[NMAX];
GetRandNumber(a,NMAX,NUMBERSTART,NUMBEREND+1);
show(a,NMAX);
return 0;
}
#include<ctime>
#include<set>
GetRandNumber(int *a,int n,int s,int e)
{
int i,j;
std::set<int> m;
std::set<int>::iterator setpos;
srand(time(NULL));
while(m.size()<n)
{
j=rand()%(e-s)+s;
m.insert(j);
}
i=0;
for(setpos=m.begin();setpos!=m.end();setpos++)
a[i++]=*setpos;
}
void show(int a[],int n)
{
using namespace std;
double sum=a[0];
double ave=0;
for(int i=0;i<n;i++)
{
cout<<a[i]<<' ';
sum+=a[i];
}
cout<<endl;
ave=sum/n;
cout<<"★★平均数是★★:"<<ave<<endl;
cout<<"★★★随机数的和是★★★:"<<sum<<endl;
//putchar('n');
}
int main()
{
using namespace std;
system ("color e");
cout<<" ★月护王★"<<endl<<" QQ:584033744"<<endl;
const int NMAX=20;
const int NUMBERSTART=1;
const int NUMBEREND=100;
cout<<"★★★★★生成"<<NMAX<<"个"<<"从"<<NUMBERSTART<<"到"<<NUMBEREND<<"的随机数★★★★★:\n";
int a[NMAX];
GetRandNumber(a,NMAX,NUMBERSTART,NUMBEREND+1);
show(a,NMAX);
return 0;
}