Wednesday, September 21, 2016

Number (BINARY) Pattern :)

Tags

#include<iostream>
#include<conio.h>
using namespace std;
main()
{
  int i,j,n;
  cout<<"Enter number of lines: ";
  cin>>n;
  for(i=1;i<=n;i++) //tells number of rows and controls inner loop
  {
    for(j=1;j<=i;j++) //tells number of digits in a row
    {
      cout<<j%2; //for printing 101010..
    }
    cout<<"\n"; //jumping in next row
  }
  getch();
}
output:
Enter number of rows: 5
1
10
101
1010
10101