Program to print inverted right triangle alphabet pattern

A B C D E
A B C D
A B C
A B
A
 

Problem Statement:- Program to print inverted right triangle alphabet pattern.

Sample Input/Output:-


Sample Input First:E

Sample Output First: 

A B C D E
A B C D
A B C
A B
A

Sample Input Second: F


Sample Output Second: 

A B C D E F
A B C D E
A B C D
A B C
A B
A

Data requirement:-


  Input Data:- row_size


  Output Data:- in


  Additional Data:- out


Program in C

Here is the source code of the C Program to print an inverted right triangle alphabet pattern.


Code:


#include<stdio.h>
int main()
{
  printf("Enter the row and column size:");
  int out,in;
  char row_size;
  scanf("%c",&row_size);
  for(out=row_size;out>='A';out--)
  {
   for(in='A';in<=out;in++)
    printf("%c ",in);
   printf("\n");
  }
}

Input/Output:
Enter the row and column size:E
A B C D E
A B C D
A B C
A B
A

 
Program in C++

Here is the source code of the C++ Program to print an inverted right triangle alphabet pattern.


Code:


#include<iostream>
using namespace std;
int main()
{
  cout<<"Enter the row and column size:";
  int out,in;
  char row_size;
  cin>>row_size;
  for(out=row_size;out>='A';out--)
  {
   for(in='A';in<=out;in++)
    cout<<char(in)<<" ";
        cout<<"\n";
}}

Input/Output:
Enter the row and column size:F
A B C D E F
A B C D E
A B C D
A B C
A B
A

Program in Java

Here is the source code of the Java Program to print an inverted right triangle alphabet pattern.


Code:


import java.util.Scanner;
public class p19 {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);    
    System.out.println("Enter the row and column size:");
    char out,in;
    char row_size=cs.next().charAt(0);
    for(out=row_size;out>='A';out--)
    {
     for(in='A';in<=out;in++)
     System.out.print(in+" ");
     System.out.println();
    }
    cs.close();
}
}

Input/Output:
Enter the row and column size:
D
A B C D 
A B C 
A B 


 
Program in Python

Here is the source code of the Python Program to print an inverted right triangle alphabet pattern.


Code:


print("Enter the row and column size:");
row_size=input()
for out in range(ord(row_size),ord('A')-1,-1):
    for i in range(ord('A'),out+1):
        print(chr(i),end=" ")
    print("\r")
Input/Output:
Enter the row and column size:
E
A B C D E 
A B C D 
A B C 
A B 
A


Post a Comment

0 Comments