C语言实现关机的程序示例如下:
立即关机
```c
include include int main() { system("shutdown -s"); return 0; } ``` ```c include include int main() { char cmd = "shutdown -s -t "; char t = "60"; // 设置延迟时间为60秒 strcat(cmd, t); system(cmd); return 0; } ``` ```c include include int main() { system("shutdown -a"); return 0; } ``` ```c include include include int main() { char input = {0}; char cmd = "shutdown -s -t "; char t = "60"; strcat(cmd, t); while (1) { printf("你的电脑将在%d秒后关机,如果输入“我是猪”,则取消关机。\n", 60); scanf("%s", input); if (strcmp(input, "我是猪") == 0) { system("shutdown -a"); break; } } return 0; } ``` 这些示例展示了如何使用C语言中的`system()`函数来执行Windows的关机命令。根据实际需求,可以选择合适的代码片段来实现立即关机、定时关机或取消关机功能。定时关机
取消关机
带输入提示的定时关机