A A A A A
B B B B
C C C
D D
E
Problem Statement:- Program to Print the Inverted Half Pyramid Alphabet Pattern.
Sample Input/Output:-
Data requirement:-
Input Data:- row_size
Output Data:- out
Additional Data:-in or inn(for python)
Program in C
Here is the source code of the C Program to Print the Inverted Half Pyramid Alphabet Pattern.
Code:
#include <stdio.h>int main(){ printf("Enter the row size(In Alphabet):"); int out, in; char row_size; scanf("%c", &row_size); for (out = 'A'; out <= row_size; out++) { for (in = row_size; in >= out; in--) printf("%c ", out); printf("\n"); }}
#include <stdio.h>int main(){ printf("Enter the row size(In Alphabet):"); int out, in; char row_size; scanf("%c", &row_size); for (out = 'A'; out <= row_size; out++) { for (in = row_size; in >= out; in--) printf("%c ", out); printf("\n"); }}
Enter the row size(In Alphabet):E
A A A A A
B B B B
C C C
D D
E
Program in C++
Here is the source code of the C++ Program to Print the Inverted Half Pyramid Alphabet Pattern.
Code:
#include <iostream>using namespace std;int main(){ cout << "Enter the row size(In Alphabet):"; int out, in; char row_size; cin >> row_size; for (out = 'A'; out <= row_size; out++) { for (in = row_size; in >= out; in--) cout << char(out) << " "; cout << "\n"; }}
#include <iostream>using namespace std;int main(){ cout << "Enter the row size(In Alphabet):"; int out, in; char row_size; cin >> row_size; for (out = 'A'; out <= row_size; out++) { for (in = row_size; in >= out; in--) cout << char(out) << " "; cout << "\n"; }}
Enter the row size(In Alphabet):D
A A A A
B B B
C C
D
Program in Java
Here is the source code of the Java Program to Print the Inverted Half Pyramid Alphabet Pattern.
Code:
import java.util.Scanner;
public class InvertedHalfPyramidAlphabetPattern {
public static void main(String[] args) { Scanner cs = new Scanner(System.in); System.out.println("Enter the row size(In Alphabet):"); char out, in; char row_size = cs.next().charAt(0); for (out = 'A'; out <= row_size; out++) { for (in = row_size; in >= out; in--) System.out.print(out + " "); System.out.println(); } cs.close(); }}
import java.util.Scanner;
public class InvertedHalfPyramidAlphabetPattern {
public static void main(String[] args) { Scanner cs = new Scanner(System.in); System.out.println("Enter the row size(In Alphabet):"); char out, in; char row_size = cs.next().charAt(0); for (out = 'A'; out <= row_size; out++) { for (in = row_size; in >= out; in--) System.out.print(out + " "); System.out.println(); } cs.close(); }}
Enter the row size(In Alphabet):F
A A A A A A
B B B B B
C C C C
D D D
E E
F
Program in Python
Here is the source code of the Python Program to Print the Inverted Half Pyramid Alphabet Pattern.
Code:
row_size = input("Enter the row size(In Alphabet):")for out in range(ord('A'), ord(row_size)+1): for i in range(ord(row_size), out-1, -1): print(chr(out), end=" ") print("\r")
row_size = input("Enter the row size(In Alphabet):")for out in range(ord('A'), ord(row_size)+1): for i in range(ord(row_size), out-1, -1): print(chr(out), end=" ") print("\r")
Enter the row size(In Alphabet):E
A A A A A
B B B B
C C C
D D
E
0 Comments
Please do not Enter any spam link in the comment box