[3876 views]

Floyd's Triangle is a right angled triangle which consists of natural numbers. The numbers start from 1 and then consecutively fills up the rest of the rows. The frequency of natural numbers in each row is equal to the row number. Therefore, n^{th} row will contain n number of consecutive natural numbers. The total natural numbers in the triangle which has n rows will be: n*(n+1)/2.

Let us consider an example:

If the number of rows = 4, Floyd's Triangle will be:

1

2 3

4 5 6

7 8 9 10

If the number of rows = 6, Floyd's Triangle will be:

1

2 3

4 5 6

7 8 9 10

11 12 13 14 15

16 17 18 19 20 21

Let us take a look at the algorithm and flowchart to print Floyd's Triangle for a given number of rows.

The algorithm starts by taking the number of rows from the user and storing it in a variable, say 'n'. To print Floyd's Triangle, we will need two loops. One loop keeps track of the rows and another prints the numbers consecutively in each row. We will also need a variable to keep track of the consecutive natural numbers to be printed in each row.

Once we get the number of rows from the user, we initialize a variable, say 'k', with the value 1. We will use this variable to print the numbers in each row in a consecutive manner. We will now start a loop with an initial value i = 1. This loop will run 'n' times. Hence, this loop is used to iterate through each row. Under this loop, we start another loop that will run from 1 to 'i'. In this loop, we print the value of k and then increment it by one. In this manner, the numbers are printed sequentially. Once this loop stops its iteration, we print a new line. This marks the end of one row. When the outer loop starts its new iteration, a new row is started. Once the outer loop completes its execution, the complete Floyd's Triangle is printed.

- Java IDE Online
- Python IDE Online
- JSON Formatter/Minifier Online
- Case Converter
- Reverse String
- HTML Encoder
- HTML Decoder
- URL Encoder
- URL Decoder
- Decimal To Binary
- Binary To Decimal
- Decimal To Octal
- Binary To Octal
- Decimal To Hexadecimal
- Hexadecimal To Decimal
- Hexadecimal To Binary
- Octal To Decimal
- Octal to Hexadecimal
- Octal to Binary
- Calculate String Length
- Remove Spaces
- Remove Line Breaks
- Remove Empty Lines
- Remove Duplicate Lines
- Word Counter
- Replace Space with hyphen
- Check Armstrong number
- Text to URL

- Algorithm and Flowchart to find the prime factors of a number
- Algorithm and Flowchart to check whether a number is twisted prime or not
- Flowchart and Algorithm for Converting Infix to Postfix notation
- Algorithm and Flowchart to Calculate Fibonacci series up to n
- Algorithm and Flowchart to Check whether a number is a Perfect Square