生成随机数(数字,大小字母)
2012-05-17 16:24:11 来源:WEB开发网核心提示:#include <iostream>#include <stdlib.h>#include <time.h>using namespace std;int main(void){ int ran_num; srand((unsigned)time(NULL)); for (int
#include <iostream> #include <stdlib.h> #include <time.h> using namespace std; int main(void) { int ran_num; srand((unsigned)time(NULL)); for (int i=0; i<4; i++) { switch((rand()%3)) { case 1: ran_num = 65; ran_num += rand()%26; putchar(ran_num); break; case 2: ran_num = 97; ran_num += rand()%26; putchar(ran_num); break; default: ran_num = 48; ran_num += rand()%9; putchar(ran_num); break; } } cout<<endl; return 0; }
更多精彩
赞助商链接