Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 55: Write a C++ program to print the Floyd’s triangle.

#include<iostream>
using namespace std;

int main()
{
	int num,n=0;
	cout<<"\nenter the number of terms : ";
	cin>>num;
	cout<<"\nFloyd's Triangle :- \n";

	for(int i=0;i<num;i++)
	{
		if(i%2!=0)
		{
			cout<<"0\t";
			n=0;
		}
		else
		{
			cout<<"1\t";
			n=1;
		}
		for(int j=1;j<=i;j++)
		{
			if(n==0)
			cout<<"1\t";
			else
			cout<<"0\t";
		}
		cout<<"\n";
	}
	return 0;
}



If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.