E E D D C C B B A
Problem Statement:- Program to Print the V Shape Alphabet Pattern.
Input Data:- row_size
Output Data:- out
Additional Data:-in or inn(for python), print_control_x, print_control_y
Program in C
Here is the source code of the C Program to Print the V Shape Alphabet Pattern.
Code:
#include <stdio.h>int main(){ int out, in; printf("Enter the row size:"); int row_size; scanf("%d", &row_size);
int print_control_x = 1; int print_control_y = row_size * 2 - 1;
for (out = row_size; out >= 1; out--) { for (in = 1; in <= row_size * 2; in++) { if (in == print_control_x || in == print_control_y) { printf("%c", out + 64); } else { printf(" "); } } print_control_x++; print_control_y--; printf("\n"); }}
#include <stdio.h>int main(){ int out, in; printf("Enter the row size:"); int row_size; scanf("%d", &row_size);
int print_control_x = 1; int print_control_y = row_size * 2 - 1;
for (out = row_size; out >= 1; out--) { for (in = 1; in <= row_size * 2; in++) { if (in == print_control_x || in == print_control_y) { printf("%c", out + 64); } else { printf(" "); } } print_control_x++; print_control_y--; printf("\n"); }}
Enter the row size:5
E E
D D
C C
B B
A
Program in C++
Here is the source code of the C++ Program to Print the V Shape Alphabet Pattern.
Code:
#include <iostream>using namespace std;int main(){ int out, in, p; cout << "Enter the row size:"; int row_size; cin >> row_size;
int print_control_x = 1; int print_control_y = row_size * 2 - 1; for (out = row_size; out >= 1; out--) { for (in = 1; in <= row_size * 2; in++) { if (in == print_control_x || in == print_control_y) { cout << char(out + 64); } else { cout << " "; } } print_control_x++; print_control_y--; cout << "\n"; }}
#include <iostream>using namespace std;int main(){ int out, in, p; cout << "Enter the row size:"; int row_size; cin >> row_size;
int print_control_x = 1; int print_control_y = row_size * 2 - 1; for (out = row_size; out >= 1; out--) { for (in = 1; in <= row_size * 2; in++) { if (in == print_control_x || in == print_control_y) { cout << char(out + 64); } else { cout << " "; } } print_control_x++; print_control_y--; cout << "\n"; }}
Output:
Enter the row size:4
D D
C C
B B
A
Program in Java
Here is the source code of the Java Program to Print the V Shape Alphabet Pattern.
Code:
import java.util.Scanner;public class VShapeAlphabetPattern{
public static void main(String[] args) { Scanner cs=new Scanner(System.in); System.out.println("Enter the row size:"); int out,in; int row_size=cs.nextInt(); int print_control_x=1; int print_control_y=row_size*2-1; for(out=row_size;out>=1;out--) { for(in=1;in<=row_size*2;in++) { if(in==print_control_x || in==print_control_y) { System.out.print((char)(out+64)); } else { System.out.printf(" "); } } print_control_x++; print_control_y--; System.out.println(); } cs.close();
}}
import java.util.Scanner;public class VShapeAlphabetPattern{
public static void main(String[] args) { Scanner cs=new Scanner(System.in); System.out.println("Enter the row size:"); int out,in; int row_size=cs.nextInt(); int print_control_x=1; int print_control_y=row_size*2-1; for(out=row_size;out>=1;out--) { for(in=1;in<=row_size*2;in++) { if(in==print_control_x || in==print_control_y) { System.out.print((char)(out+64)); } else { System.out.printf(" "); } } print_control_x++; print_control_y--; System.out.println(); } cs.close();
}}
Input/Output:
Enter the row size:
5
E E
D D
C C
B B
A
Program in Python
Here is the source code of the Python Program to Print the V Shape Alphabet Pattern.
Code:
row_size = int(input("Enter the row size:"))print_control_x = 1print_control_y = row_size*2-1for out in range(row_size, 0, -1): for inn in range(1, row_size*2+1): if inn == print_control_x or inn == print_control_y: print((chr)(out+64), end="") else: print(" ", end="") print_control_x += 1 print_control_y -= 1 print("\r")
row_size = int(input("Enter the row size:"))print_control_x = 1print_control_y = row_size*2-1for out in range(row_size, 0, -1): for inn in range(1, row_size*2+1): if inn == print_control_x or inn == print_control_y: print((chr)(out+64), end="") else: print(" ", end="") print_control_x += 1 print_control_y -= 1 print("\r")
Input/Output:
Enter the row size:3
C C
B B
A
0 Comments
Please do not Enter any spam link in the comment box