1234
123
12
1
The total number of rows is 4.
The numbers in each row start from 1 and decrease in count as we move downward:
Row 1 → 1234 ( 4 numbers)
Row 2 → 123 (3 numbers)
Row 3 → 12 (2 numbers)
Row 4 → 1 (1 number)
The outer loop runs from 0 to total_rows - 1.
The inner loop prints numbers from 1 to total_rows - row.
Java |
public class Main { public static void main(String[] args) { int total_rows = 4; // Number of rows // Outer loop for rows (starting from 0) for (int row = 0; row < total_rows; row++) { // Inner loop for columns (printing decreasing numbers) for (int col = 1; col <= total_rows - row; col++) { System.out.print(col); } System.out.println(); // Move to the next line } } } |
C++ |
#include <iostream> using namespace std; int main() { int total_rows = 4; // Number of rows // Outer loop for rows (starting from 0) for (int row = 0; row < total_rows; row++) { // Inner loop for columns (printing decreasing numbers) for (int col = 1; col <= total_rows - row; col++) { cout << col; } cout << endl; // Move to the next line } return 0; } |
Python |
total_rows = 4 # Number of rows # Outer loop for rows (starting from 0) for row in range(total_rows): # Inner loop for columns (printing decreasing numbers) for col in range(1, total_rows - row + 1): print(col, end="") print() # Move to the next line |