Shut down the Computer in C programming by using the system() function to shut down the computer. system() function takes one string parameter, the parameter will be the path of the shutdown file.
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
char ch;
printf("Do you want to shutdown your computer now (y/n)\n");
scanf("%c", &ch); //user enter character storing in 'ch'.
if(ch == 'y' || ch == 'Y') //if 'ch' value Equal to 'y' OR 'Y' then
{
system("C:\\WINDOWS\\System32\\shutdown /s"); //Shutdown Computer.
}
getch();
}