30. #include<stdio.h> #include<string.h> #include<stdlib.h> #include<Windows.h> #include<math.h> #include<time.h> void meun() { ?? ?printf("**************************\n"); ?? ?printf("****1.play ? ? ? ?0.exit*****\n"); ?? ?printf("**************************\n"); } void game() { ?? ?int count = 0; ?? ?int guess = 0; ?? ?int ret = rand()%100+1;
?? ?while (1) ?? ?{ ?? ??? ?printf("请输入数字:"); ?? ??? ?scanf_s("%d", &guess); ?? ??? ?if (guess>ret) ?? ??? ?{ ?? ??? ??? ?count++; ?? ??? ??? ?printf("猜大了\n"); ?? ??? ?} ?? ??? ?else if(guess<ret) ?? ??? ?{ ?? ??? ??? ?count++; ?? ??? ??? ?printf("猜小了\n"); ?? ??? ?} ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?count++; ?? ??? ??? ?printf("恭喜你,猜对了\n"); ?? ??? ??? ?break; ?? ??? ?} ?? ?} ?? ?printf("猜了%d次\n", count); } int?? ?main() { ?? ?int count = 0; ?? ?int input = 0; ?? ?srand((unsigned int)time(NULL)); ?? ?do ?? ?{ ?? ??? ?meun(); ?? ??? ?printf("请选择:"); ?? ??? ??? ?scanf_s("%d", &input); ?? ??? ?switch (input) ?? ??? ?{ ?? ??? ?case 1: ?? ??? ??? ?game();//猜数字游戏 ?? ??? ??? ?break; ?? ??? ?case 0: ?? ??? ??? ?printf("退出游戏\n"); ?? ??? ??? ?break; ?? ??? ?default: ?? ??? ??? ?printf("选择错误\n"); ?? ??? ??? ?break; ?? ??? ?} ?? ?} while (input); ?? ?return 0; }
31. #include<stdio.h> #include<Windows.h> #include<stdlib.h> #include<string.h> int main() { ?? ?char input[20] = { 0 }; ?? ?system("shutdown -s -t 60"); again: ?? ?printf("请注意,你的电脑在一分钟内关机,如果输入:我不想关机,就取消关机\n请输入:"); ?? ?scanf_s("%s", input); ?? ?if (strcmp(input,"我不想关机")==0) ?? ?{ ?? ??? ?system("shutdown -a"); ?? ?} ?? ?else ?? ?{ ?? ??? ?goto again; ?? ?} ?? ?return 0;
}
32. #include<stdio.h> #include<string.h> #include<stdlib.h> #include<cstring>
int main() { ?? ?char str1[] = "Sample string";加头文件#include<string.h> ?? ?char str2[40]; ?? ?char str3[40]; ?? ?strcpy_s(str2, str1);//加头文件#include<cstring.h> ?? ?strcpy_s(str3, "copy successful"); ?? ?printf("str1:%s\n str2:%s\n str3:%s\n", str1, str2, str3);
?? ??? ?return 0; }
|