Algorithm and Flowchart to display Floyd’s Triangle

[2598 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, 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:
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.

Algorithm to display Floyd's Triangle:

Step 1. Start Step 2. Read the number of rows from the user, say 'n' Step 3. Initialize variable k = 1 Step 4. Initialize loop variable i = 1 Step 5: Repeat while i <= n: 5.1: Initialize loop variable j = 1 5.2: Repeat while j <= i: 5.2.a: Print the value of k 5.2.b: Increment the value of k 5.2.c: Increment loop variable j 5.3: Print a new line 5.4: Increment loop variable i Step 6: Stop

Explanation:

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.

Flowchart to display Floyd's Triangle:

Algorithm and Flowchart to display Floyd's Triangle
Remove WaterMark from Above Flowchart

                 



Want to Learn How to write own Algorithm and Flowcharts



Want to test your logical skills in Algorithms?




Comments










Search Anything:

Sponsored Deals ends in



Interesting Technical Quizzes:

Search Tags

    Floyds Triangle Pseudocode

    Floyds Triangle Flowchart

    Flowchart for Floyds Triangle