Print Floyd Triangle Program in C++

Google Advertisements

Prev Tutorial Next Tutorial

C++ Program to Print Floyd Triangle

A Floyd's triangle is a right angled triangle of natural numbers arranged in increasing order from left to right such that Nth row contains N numbers.

For write this code we first take number of rows of Floyd's triangle as input from user and store it in a variable rows. Then using two for loops we will print N consecutive natural numbers in Nth row. Here outer for loop prints one row in every iteration where as inner for loop prints numbers of one row.

To understand below example, you have must knowledge of following C++ programming topics; Print Triangle of Stars in C++, for looping statements we need know For Loop in C++.

Examples To C++ Program to Print Floyd Triangle

Example

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21

C++ Program to Transpose Matrix

#include<iostream.h>
#include<conio.h>

void main() 
{
    int i, j, rows, counter;
  
    cout <<"Enter The Number of Rows of Floyd's Triangle\n";
    cin>>rows;
  
    // Print Floyd's triangle
    for (counter = 1, i = 1; i <= rows; i++) {
     // Print ith row 
        for (j = 1; j <= i; j++) {
            cout << counter++ << " ";
        }
        cout<<endl;
    }
 getch();
}

Output

Enter The Number of Rows of Floyd's Triangle
5
1
2  3
4  5  6
7  8  9 10
11 12 13 14 15
c++ program to print floyd triangle
Prev Tutorial Next Tutorial

Google Advertisements

We have more than 5 Groups which have 500000+ Members and some Pages have more than 100000+ members. For Advertisement contact on hitesh.xc@gmail.com or 9999595223

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Classpath variable is set for providing a path for predefined Java classes which is used in our application. All classes are available in lib/rt.jar so we set classpath upto lib/rt.jar. Difference between path and classpath in Java

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user. Cloud Computing Tutorial

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects. Download Java C C++ Projects

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: hitesh.xc@gmail.com or 8076671483 Try this Keyword C++ Programs