题目详情:电脑运行起来后,1分钟内关机。如果输入:我是猪,就取消关机
(1)goto语句代码如下:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
//关机程序
int main()
{
char input[20] = { 0 };
system("shutdown -s -t 60");
again:
printf("请注意,你的电脑在60秒内关机,如果输入:我是猪,就取消关机\n");
scanf("%s", input);
if (strcmp(input, "我是猪") == 0)
{
system("shutdown -a");
}
else
{
goto again;
}
return 0;
}
运行结果:
首先屏幕会弹出一个弹窗提示系统即将关机,随后输入即可取消关机,如果1分钟没输入就关机。
(2)while循环代码如下:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
char input[20] = { 0 };
system("shutdown -s -t 60");
while (1)
{
printf("请注意,你的电脑在60秒内关机,如果输入:我是猪,就取消关机\n");
scanf("%s", input);
if (strcmp(input, "我是猪") == 0)
{
system("shutdown -a");
break;
}
}
return 0;
}
运行结果: