Program to print the right triangle Alphabet pattern


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

Problem Statement:- Program to print the right triangle Alphabet pattern.

Sample Input/Output:-


Sample Input First: E

Sample Output First: 

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

Sample Input Second: D


Sample Output Second: 

A
A B
A B C
A B C D

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 the 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='A';out<=row_size;out++)
  {
   for(in='A';in<=out;in++)
    printf("%c ",in);
   printf("\n");
  }
}

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

Program in C++

Here is the source code of the C++ Program to print the 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='A';out<=row_size;out++)
  {
   for(in='A';in<=out;in++)
    cout<<char(in)<<" ";
        cout<<"\n";
}}

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


Program in Java

Here is the source code of the C Program to print the right triangle Alphabet pattern.


Code:


import java.util.Scanner;
public class p17 {
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='A';out<=row_size;out++)
    {
     for(in='A';in<=out;in++)
     System.out.print(in+" ");
     System.out.println();
    }
    cs.close();
}
}

Input/Output:
Enter the row and column size:
F

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


Program in Python

Here is the source code of the Python Program to print the right triangle Alphabet pattern.


Code:


print("Enter the row and column size:");
row_size=input()
for out in range(ord('A'),ord(row_size)+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 
A B C 
A B C D 

A B C D E

Post a Comment

0 Comments