C++ program to print 0 10 010 1010 pattern using class

Note: Use new compiler (Code blocks or Dev C++)  to run these C++ programs. Old  Turbo C compiler does not supports some new features of C++.

If you want to run these programs on old Turbo C++ compiler use <iostream.h> instead of <iostream> , do not use ( using namespace std; ) , use { getch(); } to hold run-time screen , use void main() instead of int main() .



0
   1 0
      0 1 0
         1 0 1 0
            0 1 0 1 0
#include<iostream>

class pattern
{
  public:

   void display()
   {
     int i, j, k = 1;
    
      for(i=1; i<=5; i++)
      {
        for(j=1; j<=i; j++)
        {
          if( k % 2  == 0 )
           cout << "1";
          else
           cout << "0";
     
           k++;
         }
         cout << "\n";
      }
    }
 };

int main()
{
  pattern  x;
  x.display();
  return 0;
 }

Comments

Popular posts from this blog

C++ program to print number pyramid 1 121 12321 1234321 using class.

A simple C++ program using class