C++ Exercises: Print the Floyd's Triangle
C++ For Loop: Exercise-43 with Solution
Write a C++ program to print Floyd's Triangle.
Sample Solution:
C++ Code :
#include <iostream>
using namespace std;
int main()
{
int i,j,n,p,q;
cout << "\n\n Print the Floyd's Triangle:\n";
cout << "--------------------------------\n";
cout << " Input number of rows: ";
cin >> n;
for(i=1;i<=n;i++)
{
if(i%2==0)
{
p=1;q=0;
}
else
{
p=0;q=1;
}
for(j=1;j<=i;j++)
if(j%2==0)
cout<<p;
else
cout<<q;
cout<<endl;
}
}
Sample Output:
Print the Floyd's Triangle: -------------------------------- Input number of rows: 5 1 01 101 0101 10101
Flowchart:

C++ Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a program in C++ to display the pattern like a pyramid using asterisk and each row contain an odd number of asterisks.
Next: Write a program in C++ to display the pattern like a diamond.
What is the difficulty level of this exercise?
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join