随机点名程序实现

代码:test.cpp

#include
#include
#include
#include
using namespace std;

int main(){
    srand(time(NULL));
    //种下随机种子,否则rand()函数返回的是伪随机数
    string name[] = {"zhangsan","lisi","zhaoliu","wangwu"};
    int len = sizeof(str)/sizeof(str[0]);
    cou t<< str[rand()%len] << endl;//输出随机到的名字
    return 0;
}

执行结果:

随机点名程序实现_第1张图片

你可能感兴趣的:(编程练习)