![]() |
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 These are the following approaches: Table of Content Approach 1: Using nested LoopUsing 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
Output
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 Approach 2: Using RecursionThe recursion approach recursively prints a reverse Floyd pattern triangle pyramid. It decreases the number of rows in each call, printing descending numbers per row until reaching the base case of zero rows. Example: The function myFunction recursively generates a reverse Floyd pattern triangle pyramid. It decreases rows in each call, printing descending numbers per row until reaching zero rows. Javascript
Output
21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 |
Reffered: https://www.geeksforgeeks.org
JavaScript |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |