A
BC
DEF
GHIJ
1)Require minimum 2 nested loop
2)Outer loop is for row
3)Inner loop is for column
4)Print in inner loop
Observations:
Java |
public class Main { public static void main(String[] args) { int total_rows = 4; // Number of rows char ch = 'A'; // Starting character // Outer loop for rows for (int row = 0; row <total_rows; row++) { // Inner loop for columns (printing letters) for (int col = 0; col <= row; col++) { System.out.print(ch); ch++; // Move to the next character } System.out.println(); // Move to the next line after each row } } } |
C++ |
#include <iostream> using namespace std; int main() { int total_rows = 4; // Number of rows char ch = 'A'; // Starting character // Outer loop for rows for (int row = 0; row <total_rows; row++) { // Inner loop for columns (printing letters) for (int col = 0; col <= row; col++) { cout << ch; ch++; // Move to the next character } cout << endl; // Move to the next line after each row } return 0; } |
Python |
total_rows = 4 # Number of rows ch = ord('A') # Convert 'A' to its ASCII value # Outer loop for rows for row in range(0, total_rows ): # Inner loop for columns (printing letters) for col in range(row): print(chr(ch), end="") # Convert ASCII to character ch += 1 # Move to the next character print() # Move to the next line after each row |