Page 46 - DCAP404 _Object Oriented Programming
P. 46

Unit 2: Beginning of OOP Language




          0                                                                                     Notes
          1
          2
          3

          4
          5
          6
          7

          8
          9
          This program can be written more conspicuously as:
          #    include  <  iostream.h>

          main  (  )                   /  *  display  the  integers  0  through  9  */
          {
                 int  digit  =  0;
                 while  (digit  <  =    9)  {
                         cout<<digit<<endl;
                         digit  +  =  5;
          }
          when executed, this program will generate the same output as the first program.

          The following code generates the Fibonacci series between 1 and 100. In this series, each number
          is the sum of its two preceding numbers. The series starts with 1.

          #  include  <  iostream  .h>
          int  main  (  )
          {
                 int  numl  =  1,    num2  =  1;
                 cout  <<  numl  <<  endl;
                 while  (  num2  <  100)
                 {
                         cout  <<  num2  <<  endl;
                         num2  +=  num1;

                         numl  =  num2  -  num1;
                 }
                 return  0;
          }







                                           LOVELY PROFESSIONAL UNIVERSITY                                   39
   41   42   43   44   45   46   47   48   49   50   51