****
***
**
*
The total number of rows is 4.
The number of stars (*) in each row decreases as we move downward:
The outer loop runs from 0 to total_rows - 1.
The inner loop prints stars, starting from total_rows - row stars in each 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 stars) for (int col = 0; col < total_rows - row; col++) { System.out.print("*"); } 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 stars) for (int col = 0; col < total_rows - row; col++) { cout << "*"; } 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 stars) for col in range(total_rows - row): print("*", end="") print() # Move to the next line |