In this tutorial, we will discuss the C program to Floyd’s triangle binary pattern.
In this post, we will learn how to displayed Floyd’s triangle binary pattern using for loop or nested for loop in C programming language
here, we displayed some binary Floyd’s triangle program with coding using nested for loop and also we get input from the user using Scanner class in Java language
the user can provide numbers as they wish and get the binary pattern according to their input
program 1
#include <stdio.h> #include <stdlib.h> int main() { int i,j,rows; printf("Enter the number of rows: "); scanf("%d",&rows); for(i=1; i<=rows; i++){ for(j=1; j<=i; j++){ if(i%2==1) { printf("1"); } else{ printf("0"); } } printf("\n"); } getch(); return 0; }
When the above code executed, it produces the following results
Enter the number of rows: 6 1 00 111 0000 11111 000000 1111111 00000000
Program 2
#include <stdio.h> #include <stdlib.h> int main() { int i,j,rows; printf("Enter the number of rows: "); scanf("%d",&rows); for(i=1; i<=rows; i++){ for(j=1; j<=i; j++){ if(j%2==1) { printf("1"); } else{ printf("0"); } } printf("\n"); } getch(); return 0; }
When the above code executed, it produces the following results
Enter the number of rows: 8 1 10 101 1010 10101 101010 1010101 10101010
Program 3
#include <stdio.h> #include <stdlib.h> int main() { int i,j,rows; printf("Enter the number of rows: "); scanf("%d",&rows); for(i=1; i<=rows; i++){ for(j=1; j<=i; j++){ if(j%2==1) { printf("0"); } else{ printf("1"); } } printf("\n"); } getch(); return 0; }
When the above code executed, it produces the following results
Enter the number of rows: 8 0 01 010 0101 01010 010101 0101010 01010101
Program 4
#include <stdio.h> #include <stdlib.h> int main() { int i,j,rows; int num=1; printf("Enter the number of rows: "); scanf("%d",&rows ); for(i=1; i<=rows; i++){ for(j=1; j<=i; j++){ printf("%d",num); num=!num; } num=i%2; printf("\n"); } getch(); return 0; }
When the above code executed, it produces the following results
Enter the number of rows: 8 1 10 010 1010 01010 101010 0101010 10101010
Program 5
#include <stdio.h> #include <stdlib.h> int main() { int i,j,rows; printf("Enter the number of rows: "); scanf("%d",&rows); for(i=1; i<=rows; i++){ for(j=1; j<=i; j++){ if((i+j)%2==1){ printf("0"); } else{ printf("1"); } } printf("\n"); } return 0; }
When the above code executed, it produces the following results
Enter the number of roes: 8 1 01 101 0101 10101 010101 1010101 01010101
Program 6
#include <stdio.h> #include <stdlib.h> int main() { int i,j,rows; printf("Enter the number of rows: "); scanf("%d",&rows); for(i=1; i<=rows; i++){ for(j=1; j<=i; j++){ if((i+j)%2==1){ printf("1"); } else{ printf("0"); } } printf("\n"); } return 0; }
When the above code executed, it produces the following results
Enter the number of rows: 8 0 10 010 1010 01010 101010 0101010 10101010
Similar post
C++ program to display triangle binary pattern
Java program to display triangle binary pattern
C code to display diamond star pattern
C++ code to display diamond star pattern
C++ program to display Binary pyramid pattern
C program to display Binary pyramid pattern
C program to display hollow diamond star pattern
C++ program to display hollow diamond star pattern
Java code to print Rhombus and hollow Rhombus star pattern
C program to display Mirrored Rhombus hollow Mirrored Rhombus star pattern
C++ program to display Rhombus hollow Rhombus star pattern
Java program to display Parallelogram star pattern using while loop
C program to display Parallelogram star pattern using for loop
C++ program to display mirrored Parallelogram star pattern using for loop
Suggested for you
Nested for loop in Java language
Nested while loop in Java language
Nested for loop in C++ language
Nested while loop in C++ language
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…