#include <stdio.h>#include <stdlib.h>#include <time.h>int main(){ int a[] = { 2, 4, 6, 8, 10 }; const int NUM = sizeof(a) / sizeof(*a);
srand( time(0) ); printf( "%d/n", a[rand() % NUM] );}
收获
1 获得数组的长度
2 范围随机数