Skip to main content

Featured

functions in Python

C++ program to print pattern of alternating 0 and 1

/*program to print pattern
1
01
010
1010
10101
010101
...n times*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,k=1,n;
cout<<"\nEnter the no of lines\n";
cin>>n;
for(i=1;i<=n;i++)
{ for(j=1;j<=i;j++)
  {
   cout<<k;
   if(k==1)
   k=0;
   else
   k=1;
   }
  cout<<endl;
}
getch();
}

Comments

Popular Posts