Reputation:
How do I close the Linux terminal window after executing my C program?
#include<stdio.h>
void main()
{
int si,p,t,r;
printf("Enter p t r");
scanf("%d %d %d",&p, &t, &r);
si = (p * t * r) / 100;
printf("%d",si);
// after finishing task i want to close the terminal
}
After compiling my program in Ubuntu terminal, I run my program:
./a.out
After execution of my program, terminal should close automatically. How to do that?
Upvotes: 1
Views: 2152
Reputation: 1675
try writing system("exit") as the last line in the code. I have tried system("cls") on mingw and it worked
Upvotes: -1
Reputation: 798456
Tell your shell to exec the program instead of running it, so that it replaces the shell.
exec ./a.out
Upvotes: 2