# C program to print binary numbers right triangle pyramid pattern

• Write a program in C to print right triangle of binary number.
• How to draw a right triangle pattern of binary number using for loop in C.
For a binary number right triangle of 5 rows, program's output should be:
```1
0 1
1 0 1
0 1 0 1
1 0 1 0 1
```

#### Required Knowledge

Algorithm to print triangle pattern of binary numbers
This program is similar to right triangle star pattern. The only difference is instead of printing star characters we will print binary digits.
• Take the number of rows(N) of right triangle as input from user using scanf function.
• Number of integers in Kth row is always K.
• We will use two for loops to print right triangle of binary numbers.
• Outer for loop will iterate N time. Each iteration of outer loop will print one row of the pattern.
• Inside inner loop will toggle binary digits and print it. Each iteration of inner loop will print K alternating 0 and 1 in Kth row.

## C program to print right triangle pattern having same number in a row

```#include<stdio.h>

int main() {
int i, j, rows;
int count = 1;

printf("Enter the number of rows\n");
scanf("%d", &rows);

for (i = 1; i <= rows; i++) {
for (j = 1; j <= i; j++) {
printf("%d ", count);
count = !count;
}
count = i % 2;
printf("\n");
}
return(0);
}
```
Output
```Enter the number of rows
5
1
1 0
0 1 0
1 0 1 0
0 1 0 1 0
```

Related Topics
 C program binary rectangle pattern C program natural number triangle pattern C program hollow diamond star pattern C program hollow pyramid star pattern C program diamond star pattern C program rectangle star pattern C program inverted right triangle pattern C program palindrome triangle pattern C program rhombus star pattern List of all C pattern programs