how to write a c programme to print the numbers in following way

1
0 1
1 0 1
0 1 0 1
1 0 1 0 1
0 1 0 1 0 1

please help me

Well, here's the pattern:
Start with 1.
1) Put a zero infront of the current number.
2) Invert the number.
You can do this with a linked list, or a variable length array.
If you want to make it faster, instead of inverting the whole container, just invert what you print.
Good luck. :)

Well, here's the pattern:
Start with 1.
1) Put a zero infront of the current number.
2) Invert the number.
You can do this with a linked list, or a variable length array.
If you want to make it faster, instead of inverting the whole container, just invert what you print.
Good luck. :)

Or another faster way is using modulus operator.

[b]Pseudo code:[/b]
For i = 0 To 3
   Print i % 2
Next i

[b]Result:[/b]
0 1 0 1

i used c, long time back but still i will try...

{
int a,b,c;
a=0; b=0; //i am not sure whether to use static here or not//

if {

(a<6)

print a /n;

then(b=(a+1) */need to make some more logics so it works/*
print a;
print b;

}
a=a+1
} // Build on it.. if its right.. it was fun trying C program after 8 years.....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.