Featured
- Get link
- X
- Other Apps
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();
}
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();
}
- Get link
- X
- Other Apps
Popular Posts
C++ program to display numbers which get reversed after multiplying by 4
- Get link
- X
- Other Apps
Comments
Post a Comment