#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include<time.h>
int menu() {
printf("******************\n");
printf("****1.开始游戏****\n");
printf("****2.退出游戏****\n");
printf("******************\n");
printf("请输入您的选择");
int result;
scanf("%d", &result);
return result;
}
void game() {
int toGuess = rand() % 100 + 1;
while (1) {
printf("请输入您猜的数字:\n");
int num;
scanf("%d", &num);
if (num > toGuess)
printf("猜高了:\n");
else if (num < toGuess)
printf("猜低了:\n");
else
printf("恭喜你猜对了!\n");
}
}
int main() {
int t = time(0);
srand(t);
while (1) {
int choice=menu();
if (choice == 1) {
game();
}
else if (choice == 2) {
printf("游戏结束,请退出!\n");
break;
}
else
printf("您的输入有误请重新输入!\n");
system("pause");
}
}
```c
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int prime(int m) {
int i,n=1;
for (i = 2; i <= sqrt(m); i++) {
if (m%i == 0) {
n = 0;
break;
}
}
return n;
}
int main() {
int i,num=0;
for (i = 2; i <= 100; i++) {
if(prime(i))
num++;
}
printf("共有素数:%d个\n",num);
system("pause");
}