rand()
#include <stdio.h> #include <stdlib.h> int main() { for (int i = 0; i < 10; i++) { printf("%d\n",rand()); } system("pause"); return EXIT_SUCCESS; }
#include <stdio.h> #include <stdlib.h> int main() { for (int i = 0; i < 10; i++) { printf("%d\n",rand()%10); } system("pause"); return EXIT_SUCCESS; }
指定随机数的生成范围例如生成8以内的随机数---只不过....程序每次运行时都是生成这几个货
#include <stdio.h> #include <stdlib.h> int main() { srand(8); for (int i = 0; i < 10; i++) { printf("%d\n",rand()%10); } system("pause"); return EXIT_SUCCESS; }