by Dinesh Thakur Category: Control Structures

This function causes the program to terminate from any portion of the program and does not have any return value. It has only one argument whose value is returned to the operating system when the program is terminated. This function is included in the <stdlib.h> header file. Hence this header file must be included in the beginning of the program.

 

Example

 

To find whether a given number is prime or not using do ..while loop.

 

#include<iostream.h>
#include<math.h>
#include<stdlib.h>
#include<conio.h>
void main()
{
          int n;
          int q;
          clrscr();
          cout<<"Enter the Number : ";
          cin>>n;
          int i=2;
    do
      {
          if(n%i==0)
          goto II;
          i++;
      }
         while(i<=int( sqrt(n)));
         cout<<n<<" is a prime number ";
         exit(1);
         II:
         cout<<"Not a prime number "<<"\n";
        getch();
}

C++ program exit() function



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles