Program to Print Inverted Right-Angled Triangle with Repeated Character (Decreasing order) Pattern
In this article we are going to see how to print the Inverted Right Angle with decreasing Character program.
Example-1 When row value=4 DDDD CCC BB A
Example-2: When row value=5 EEEEE DDDD CCC BB A
Now, let’s see the actual program it.
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=row_count;row>=1;row--) { // FOR LOOP TO PRINT THE COLUMN VALUE for(col=1;col<=row ;col++) // FOR EACH COLUMN WE ARE PRINTING THE // CHARACTER ACCORDINT TO IT ASCII VALE . System.out.print((char)(row+64)); System.out.println(""); } } }
Output: Enter rows : 5 EEEEE DDDD CCC BB A
C Code:
#include <stdio.h> int main() { int row_count,row,col ; printf("Enter rows: "); scanf("%d", &row_count); for(row=row_count;row>=1;row--) { for(col=1;col<=row ;col++) printf("%c",(char)(row+64)); printf("\n"); } return 0; }
Output: Enter rows : 5 EEEEE DDDD CCC BB A
C++ Code:
#include <iostream> using namespace std; int main() { int row_count,row,col ; cout << "Enter rows: "; cin >> row_count; for(row=row_count;row>=1;row--) { for(col=1;col<=row ;col++) cout << (char)(row+64); cout << "\n"; } return 0; }
Output: Enter rows : 5 EEEEE DDDD CCC BB A
Related Java Star Pattern Programs:
- Java Program to Print Inverted Right-Angled Triangle with Increasing Character Pattern
- Java Program to Print Inverted Right-Angled Triangle with Repeated Character (Increasing order) Pattern
- Java Program to Print Inverted Right-Angled Triangle with Row wise Decreasing Character Pattern
- Java Program to Print Inverted Right-Angled Triangle with Row wise Increasing Character Pattern
- Java Program to Print Right Angled Triangle with Same Character Pattern