Pattern 41: Print Numbers pattern program in C

Spread the love

Print Numbers Pattern on Console:

Write a C Program to print numbers pattern given below using the C Language loops.

We have created the same pattern earlier but we used another method in that program. Please check that method at following link – Pattern 39: 1-0 Number Pattern in C Programming

Example 1:

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

Example 2:

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

Print Numbers Pattern Program Logic:

  • We need two For loops, The Outer for loop and Inner for loop.  The Outer for loop helps us to track the rows and Inner for loop is useful to track the column values.
  • The outer for loop will iterate from the ‘1’ to the number of rows i.e ‘n’
  • The Inner for loop goes from 1 to ‘i’ ( Here ‘i’ is the outer loop iterator ) So stopping inner loop once we reached ‘i’ creates the Triangle shape.
  • Now we got the desired shape, We need to print the values now
  • If we see above example Patterns, Each row always starts with 1 and then second value is opposite to it i.e 0. And third value is opposite to 0. which is  1 and so on
  • So We need to start the each row value with 1 and then Apply Logical Not Operator (!)  on the values for each iteration to get the desired value.
  • Which will give us 1 0 1 0 .. etc pattern. And we need stop the inner loop once we reached the ( j<=i ) ( Here ‘j’ is inner loop iterator and ‘i’ is Outer loop iterator)

📢 Also Check All Pattern Programs:

Program to print numbers pattern:

Program Output:

print-numbers-pattern-program-in-c

Similar Number Patterns:

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.

You may also like...

Leave a Reply