sir in this lecture it is said that we can switch between 0 and 1 with the help of val=1-val.
but i want to use bitwise not operator (~)in order to flip 0-1 and 1-0.
i used that in program but it shows that ~1 is -2 and ~0 is -1.
here is my code:
#include
using namespace std;
int main()
{
int n, row, col, val;
cout<<“How many rows u want to print ?”<<endl;
cin>>n;
for(row=1; row<=n; row++)
{
val = row%2==0 ? 1 : 0;
for(col=1; col<=row; col++)
{
cout<<val;
val = (~val);
}
cout<<endl;
}
return 0;
}
and the output is like this:
How many rows u want to print ?
6
0
1-2
0-10
1-21-2
0-10-10
1-21-21-2
