Page 102 - Modular_V2.0_C++_Flikpbook
P. 102

Some of the functions of the stdlib.h header file are:

                   Function Name                     Use                  Example                 Output

                   abs                It returns absolute integral value.  abs(-11)  11

                   abort              It aborts  the current  process  abort( )      Program terminated.
                                      abnormally.

                   div                It  returns  the  quotient  and  div (38,5) Quotient = 7, Remainder = 3
                                      remainder of integer division.

                   exit               It terminates the calling process.  exit(0)    Exit the program


                  Program 3: To use the functions of stdlib.h header file.
                  #include<iostream.h>

                  #include<stdlib.h>
                  #include<conio.h>
                  void main()
                  {

                      int a;
                      clrscr();
                      cout<< "Enter a number: ";
                      cin>> a;

                      if(a % 2 == 0)
                      {
                           cout<< "You have entered an even number. Operation is aborted.";

                          abort();
                      }
                      else
                      {

                          cout<< "You have entered an odd number. Program will exit.";
                          exit(0);
                      }
                      getch();

                  }
                  If you run the preceding program and enter an even number, then your program will abort
                  abnormally after printing the message. If you enter an odd number, then your program will
                  terminate. You can see the printed message by selecting the Output option from the Window
                  menu.






                   100
                          Touchpad MODULAR (Ver. 2.0)
   97   98   99   100   101   102   103   104   105   106   107