# 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 :

Â

Venkatesh

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

### 1 Response

1. Unknown or Deleted User says:

12345
5432
123
21
1