1.5 生成随机数: #include #include srand((unsigned int)time(NULL)); int red=rand(); 或者int red=rand()%101;//规定0-100的范围 猜数字小游戏: #include #include #include int main() { int start; void game(); void menu(); srand((unsigned int)time(NULL)); do { menu(); scanf("%d", &start); switch (start) { case 1: game(); break; case 0:printf("游戏结束\n"); break; default:printf("请重新输入\n"); break; } } while (start != 0); return 0; } void menu() { printf("||\n");printf("||\n"); printf("|************ 1.play *|\n"); printf("| 0.exit *************|\n"); printf("||\n");printf("||\n"); printf("请输入:>"); } void game() { int z = 0; int a = rand()%101; printf("游戏开始,祝您游戏愉快\n"); Sleep(2000); do { printf("请猜测数字,数字范围是0-100\n"); scanf("%d", &z); if (a == z) { printf("恭喜你,猜对啦\n"); break; } else if (z > a) printf("大了,换个数字再试试\n"); else if (z < a) printf("小了,换个数字再试试\n"); } while (a!=z); } 辗转相除法求最大公因数: 例如求 24 18 24%18=6 18%6=0 所以为6 7 5 7%5=2 5%2=1 2%1=1 1%1=0 所以为1
标签:1.5,int,void,break,start,printf,include From: https://www.cnblogs.com/lz-not-lzy/p/17029214.html