Using nested Loop
Using nested loops, iterate from the specified number of rows downwards, printing numbers in descending order for each row, forming a reverse Floyd pattern triangle pyramid.
Example: The function myFunction generates a reverse Floyd pattern triangle pyramid by iterating through rows downwards, printing descending numbers, and forming a triangle with decreasing lengths per row.
Javascript
function myFunction(rows) { let num = rows * (rows + 1) / 2; for (let i = rows; i >= 1; i--) { let pattern = '' ; for (let j = 1; j <= i; j++) { pattern += num-- + ' ' ; } console.log(pattern); } } myFunction(5); |
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
JavaScript Program to Print Reverse Floyd Pattern Triangle Pyramid
Printing a reverse Floyd pattern triangle pyramid involves outputting a series of numbers in descending order, forming a triangular shape with each row containing one less number than the previous row. The numbers are arranged in such a way that they form a right-angled triangle, reminiscent of Floyd’s triangle, but in reverse order.
Example:
Input: 5
Output:
15 14 13 12 11
10 9 8 7
6 5 4
3 2
1
These are the following approaches:
Table of Content
- Using nested Loop
- Using Recursion