Binary pattern

Cpp program to display triangle binary pattern

Cpp program to display triangle binary pattern

In this tutorial, we will discuss Cpp program to display 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 are displayed some binary Floyd’s triangle program with coding using nested for loop and also we get input from user using cin() input function  in C++ language

Cpp program to display triangle binary pattern

the user can provide numbers as they wish and get the binary pattern according to their input

Triangle binary pattern 1

Program 1

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int i,j,rows;
    int count_1=1;
    cout<<"Enter the number of rows: ";
        cin>>rows;
        for(i=1; i<=rows; i++){
            for(j=1; j<=i; j++){
                cout<<count_1;
                count_1=!count_1;
        }
        count_1=i%2;
        cout<<"\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

Triangle binary pattern 2

Program 2

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int i,j,rows;
    int count_1=1;
    cout<<"Enter the number of rows";
        cin>>rows;
        for(i=1; i<=rows; i++){
            for(j=1; j<=i; j++){
                cout<<count_1;
        }
        count_1=i%2;
        cout<<"\n";
        }
        getch();
    return 0;
}

When the above code executed, it produces the following results

Enter the number of rows: 8
1
11
000
1111
00000
111111
0000000
11111111

Triangle binary pattern 3

Program 3

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int i,j,rows;
    int count_1=1;
    cout<<"Enter the number of rows";
        cin>>rows;
        for(i=1; i<=rows; i++){
            for(j=1; j<=i; j++){
                if(j%2==1)
                {
                    cout<<"0";
                }
                else{
                    cout<<"1";
                }
        }
        cout<<"\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

Triangle binary pattern 4

Program 4

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int i,j,rows;
    int count_1=1;
    cout<<"Enter the number of rows: ";
        cin>>rows;
        for(i=1; i<=rows; i++){
            for(j=1; j<=i; j++){
                if(j%2==1)
                {
                    cout<<"1";
                }
                else{
                    cout<<"0";
                }
        }
        cout<<"\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

Triangle binary pattern 5

Program 5

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int i,j,rows;
    int count_1=1;
    cout<<"Enter the number of rows: ";
        cin>>rows;
        for(i=1; i<=rows; i++){
            for(j=1; j<=i; j++){
                if(i%2==1)
                {
                    cout<<"1";
                }
                else{
                    cout<<"0";
                }
        }
        cout<<"\n";
        }
        getch();
    return 0;
}

When the above code executed, it produces the following results

Enter the number of rows: 8
1
00
111
0000
11111
000000
1111111
00000000

Triangle binary pattern 6

Program 6

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int i,j,rows;
    cout << "Enter the number of rows: " << endl;
    cin>>rows;
    for(i=1; i<=rows; i++){
  for(j=1; j<=i; j++){
  if((i+j)%2==1){
      cout<<"0";
  }
  else{
      cout<<"1";
  }


}
cout<<"\n";
    }
    return 0;
}

When the above code executed, it produces the following results

Enter the number of rows:
8
1
01
101
0101
10101
010101
1010101
01010101

Triangle binary pattern 7

Program 7

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int i,j,rows;
    cout << "Enter the number of rows: " << endl;
    cin>>rows;
    for(i=1; i<=rows; i++){
  for(j=1; j<=i; j++){
  if((i+j)%2==1){
      cout<<"1";
  }
  else{
      cout<<"0";
  }


}
cout<<"\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

Operator in Java language

Data type in Java language

For loop in Java language

While loop in Java language

Nested for loop in Java language

Nested while loop in Java language

 

Operator in C++ language

Data type in C++ language

For loop in C++ language

While loop in C++ language

Nested for loop in C++ language

Nested while loop in C++ language

 

Operator in C language

For loop in C language

While loop in C language

Nested for loop in C language

Nested while loop in C language

C program to Floyd's triangle binary pattern
Java program to display triangle binary pattern
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago