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, nth 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:
4 5 6
7 8 9 10
If the number of rows = 6, Floyd's Triangle will be:
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.