Java Program to Print Inverted Right-Angled Triangle with Row wise Decreasing Character Pattern

Program to Print Inverted Right-Angled Triangle with Row wise Decreasing Character Pattern

In this article we are going to see how to print the Inverted Right Angled with Row Wise Decreasing Character Program.

Example-1

When row value=4

DCBA
DCB
DC
D
Example-2:

When row value=5

EDCBA
EDCB
EDC
ED
E

Now, let’s see the actual program to print the pattern.

Approach:

  • Enter total row and store it in an integer variable row_count.
  • Take first for loop to print all rows.
  • Take second/inner for loop to print column values.
  • Continue printing the character  according to the iteration.

JAVA Code:

import java.util.*;
public class Main 
{    
    public static void main(String args[])   
    {   // taking variable for loop iteration and row .
    int row_count,row,col ;
    //creating object 
    Scanner s = new Scanner(System.in);
    // entering the number of row
    System.out.print("Enter rows : ");
    row_count = s.nextInt();
    // FOR LOOP To HANDLE THE ROW VALUE 
      for(row=1;row<=row_count;row++)
     {
         // for loop to handel column value 
         for(col=row_count;col>=row;col--)
             // printing the result by column wise 
             // according to its ASCII value .
             System.out.print((char)(col+64));
         System.out.println("");
     }
    }
}
Output:

Enter rows : 5

EDCBA
EDCB
EDC
ED
E

C Code:

#include <stdio.h>
int main() {
   int row_count,row,col ;
   printf("Enter rows: ");
   scanf("%d", &row_count);
    for(row=1;row<=row_count;row++)
     {
         for(col=row_count;col>=row;col--)
            printf("%c",(char)(col+64));
          printf("\n");
     }
   return 0;
}
Output:

Enter rows : 5

EDCBA
EDCB
EDC
ED
E

C++ Code:

#include <iostream>
using namespace std;
int main()
{
   int row_count,row,col ;
   cout << "Enter  rows: ";
   cin >> row_count;
      for(row=1;row<=row_count;row++)
     {
         for(col=row_count;col>=row;col--)
            cout << (char)(col+64);
         cout << "\n";
     }
    return 0;
}

Output:

Enter rows : 5

EDCBA
EDCB
EDC
ED
E

Related Java Star Pattern Programs: