Binary Triangle is a Triangle formed with 1’s and 0’s.
Number of rows in the binary triangle is obtained from the user.
Here is source code of the C++ Program to Print a Binary Triangle.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#include <iostream> using namespace std; int main() { int p, lastInt = 0, input; cout<<"Enter the Number of Rows : "; cin>>input; for (int i = 1; i <= input; i++) { for (p = 1; p <= i; p++) { if (lastInt == 1) { cout<<"0"; lastInt = 0; } else if (lastInt == 0) { cout<<"1"; lastInt = 1; } } cout<<"\n"; } return 0; } |
Output:
You can find more similar examples of programming for this programming language in the site.