user2432118
user2432118

Reputation:

Close the terminal after finishing execution

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

Answers (3)

Daemon
Daemon

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

Babar Al-Amin
Babar Al-Amin

Reputation: 3984

For bash terminal

./a.out && exit

Upvotes: 1

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798456

Tell your shell to exec the program instead of running it, so that it replaces the shell.

exec ./a.out

Upvotes: 2

Related Questions