0

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

4
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by karthik viswam
0

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. :)

0

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
0

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.....

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.