程序如下.如对这个程序还有其它的要求,靖请发贴告诉我.
#include <iostream.h>
#include <time.h>
#include <stdlib.h>
main()
{
srand((unsigned)time(NULL));
int num,*a,small,count,big,k=0,i;
cout<<"输入你想要得到的平均值:";
cin>>num;
cout<<"输入这个a和b的值.\n";
cin>>small;
cin>>big;
if(small>=num||big<=num)
{
cout<<"k不在"<<small<<"与"<<big<<"之间\n";
exit(0);
}
cout<<"想要产生多少个随机数:";
cin>>count;
a=new int[count];
for(i=0;i<count-1;i++)
{
a[i]=rand()%num*2-rand()%2;
if(a[i]<num)
a[i]+=small;
k+=a[i];
if(i==count-2)
{
a[i+1]=num*count-k;
k+=a[i+1];
}
}
cout<<"产生的随机数:\n";
for(i=0;i<count;i++)
{
cout<<a[i]<<endl;
}
cout<<"随机数的总值:"<<k<<endl;
cout<<"随机数得到的平均值:";
cout<<k/count<<endl;
}