for n=5 the desired output is :-
1
01
010
1010
10101
But this code prints only the first 1 one and all other ones are printed as zeroes.
int n;
cin>>n;
int c=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
cout<<c;
if(c=1)
{
c=0
}
else{
c=1
}
}
cout<<endl;
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire