测试通过了:
#include "stdio.h"
#include "conio.h"
#include
#include
#include
main()
{
int randArray[5]={65,98,45,76,93};
int i;
double sum=0;
time_t t;
srand((unsigned)time(&t));
for(i=0;i<3;i++)
{
sum=sum+randArray[rand()%5];//随机产生数组的下标0-4之间,这样3次随机取3个就OK了
}
printf("rand 3 num Avg=%6.2lf\n",sum/3.0);
getch();
}
import random
ns = [1,2,3,4,5]
ch = random.sample(ns, 3)
mean = sum(ch)/len(ch)