Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 152 - CoreGPT(Podar)_Flipbook_C8
P. 152

    //Statements for condition1

                          if(condition2)
                          {

                               // Statements for condition2 (executed only if condition1 and
                                 condition2 are both true)
                          }

                          else
                          {

                              // Statements executed if condition2 is false
                          }

                      }
                      Program 4: To check if the number is even or odd.

                      #include<iostream.h>
                      #include<conio.h>
                      void main()
                      {                                                           Enter a number: 12

                          clrscr();                                               The number is positive.
                                                                                  It is an even number.
                          int num;
                          cout<< "Enter a number: ";
                          cin>> num;                                              Enter a number: 7
                          if(num > 0)                                             The number is positive.
                          {                                                       It is an odd number.

                              cout<< "The number is positive." << endl;
                              if(num % 2 == 0)
                              {
                                  cout<< "It is an even number." << endl;

                              }
                              else
                              {
                                  cout<< "It is an odd number." << endl;
                              }
                          }

                          getch();
                      }

                    150     Premium Edition-VIII

| 147 148 149 150 151 152 153 154 155 156 157 |