The pattern can be printed using two nested loops. The outer loop runs once for each row, while the inner loop runs for each column in that row, printing stars. After printing all the stars in a row, a newline is added to move to the next row.
C++
usingnamespacestd;intmain(){// Number of rows and columnsintn=3,m=5;// Loop through each rowfor(inti=1;i<=n;i++){// Loop through each column in the current rowfor(intj=1;j<=m;j++){cout<<"* ";}// Move to the next rowcout<<"\n";}return0;}
Java
classGFG{publicstaticvoidmain(String[]args){// Number of rows and columnsintn=3,m=5;// Loop through each rowfor(inti=1;i<=n;i++){// Loop through each column in the current rowfor(intj=1;j<=m;j++){// Print a starSystem.out.print("* ");}// Move to the next rowSystem.out.println();}}}
Python
defmain():# Number of rows and columnsn,m=3,5# Loop through each rowforiinrange(1,n+1):# Loop through each column in the current rowforjinrange(1,m+1):# Print a starprint("*",end=" ")# Move to the next rowprint()if__name__=="__main__":main()
C#
usingSystem;classGFG{staticvoidMain(){// Number of rows and columnsintn=3,m=5;// Loop through each rowfor(inti=1;i<=n;i++){// Loop through each column in the current rowfor(intj=1;j<=m;j++){// Print a starConsole.Write("* ");}// Move to the next rowConsole.WriteLine();}}}
JavaScript
// Number of rows and columnsletn=3,m=5;// driver code// Loop through each rowfor(leti=1;i<=n;i++){// Loop through each column in the current rowfor(letj=1;j<=m;j++){// Print a starprocess.stdout.write("* ");}// Move to the next rowconsole.log();}