Horje
Program to print Reverse Floyd's triangle

Floyd’s triangle is a triangle with first natural numbers. Task is to print reverse of Floyd’s triangle.
Examples: 
 

Input : 4
Output :
10 9 8 7
6 5 4 
3 2 
1 

Input : 5
Output :
15 14 13 12 11 
10 9 8 7 
6 5 4 
3 2 
1

 

 

C++

<?php
// PHP program to print reverse 
// of floyd's triangle 
function printReverseFloyd($n
    $curr_val = $n * ($n + 1) / 2; 
    for ($i = $n; $i >= 1; $i--) 
    
        for ( $j = $i; $j >= 1; $j--) 
        
            echo $curr_val-- , " "
        
  
        echo " \n"
    
  
// Driver Code 
$n = 7; 
printReverseFloyd($n); 
  
// This code is contributed by ajit 
?>

Javascript

<script>
  
// Javascript program to print reverse of
// floyd's triangle
  
function printReverseFloyd(n)
    {
        let curr_val = n * (n + 1) / 2;
        for (let i = n; i >= 1; i--) {
            for (let j = i; j >= 1; j--) {
                document.write(curr_val-- + " ");
            }
    
            document.write("<br/>");
        }
    }
  
  
// Driver Code
  
          let n = 7;
        printReverseFloyd(n);
      
</script>

Output: 

28  27  26  25  24  23  22  
21  20  19  18  17  16  
15  14  13  12  11  
10  9  8  7  
6  5  4  
3  2  
1

 

Time complexity: O(n2) for given input n

Auxiliary space: O(1)




Reffered: https://www.geeksforgeeks.org


DSA

Related
Slope of perpendicular to line Slope of perpendicular to line
Java Math incrementExact(int x) method Java Math incrementExact(int x) method
Find n-th term of series 1, 4, 27, 16, 125, 36, 343 ....... Find n-th term of series 1, 4, 27, 16, 125, 36, 343 .......
Count divisible pairs in an array Count divisible pairs in an array
Check if a string is substring of another Check if a string is substring of another

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
8