# Pattern 38: 0 1 Number Pattern Program in C Language

## 0 1 Number Pattern Program:

Write a C Program to print below 0 1 number pattern on the console using for loops.

Program will accepts the input number from the user and prints the pattern

Example 1:

Enter how many rows you want : 5
1
0 1
0 1 0
1 0 1 0
1 0 1 0 1

Example 2:

Enter how many rows you want : 10
1
0 1
0 1 0
1 0 1 0
1 0 1 0 1
0 1 0 1 0 1
0 1 0 1 0 1 0
1 0 1 0 1 0 1 0
1 0 1 0 1 0 1 0 1
0 1 0 1 0 1 0 1 0 1

## The 0 1 Number Pattern Logic:

If we see the above example programs. The Pattern starts with number 1 and then goes to number 0. Then it goes back to number 1. so on.

So here we are printing a number ( i.e 1 ) and then we will apply the Logical NOT Operator ( ! )  it. In the next iteration, We will again do the same thing applying NOT operator  ( ! )  so the value will be converted from 0 to 1.

So logic will be

• As we need Triangle shape, The pattern need to start with printing 1 value at row 1 and 2 values at row 2 and so on.
• We need two loops, Outer loop and Inner Loop. So the Outer Loop will be start from 1 to n. Representing the number of rows.
• For each Iteration of Outer loop, The inner loop will need to go from 1 to 'i''i' outer loop iterator ). Which gives us the triangle shape
• Okay, Now we know how to get the triangle shape. Now we need to print the values.
• We will start with the number  1  at the first row. Then after printing the value, We will convert the  1 to 0 using the  not ( '!' )  operator. Which converts the 1 to 0 and 0 to 1
• Then at each print apply the  not operator (!)  to the above number. So we will always have the correct number to print at next iteration.
• Repeat the above steps until we reach the number of rows ( 'n' )

## Program Output:

### Similar Star pattern programs : Venkat

Hi Guys, I am Venkatesh. I am a programmer and an Open Source enthusiast. I write about programming and technology on this blog.