Here's is the example of to print the star square pattern in c, c++, java, c#, JavaScript and python.
// Star Square pattern print in C programming language.
#include <stdio.h>
int main() {
int n;
printf("Enter the number of rows: ");
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
printf("*");
}
printf("\n");
}
return 0;
}
// Star square pattern print in c++ programming langauge.
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter the number of rows: ";
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cout << "*";
}
cout << endl;
}
return 0;
}
// Print Star Square pattern in Java programming langauge.
import java.util.Scanner;
public class StarSquare {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of rows: ");
int n = sc.nextInt();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
System.out.print("*");
}
System.out.println();
}
sc.close();
}
}
// Using python print the star square pattern.
n = int(input("Enter the number of rows: "))
for i in range(n):
for j in range(n):
print("*", end="")
print()
// Write a C# program to print the star square pattern.
using System;
public class StarSquare {
public static void Main() {
Console.Write("Enter the number of rows: ");
int n = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
Console.Write("*");
}
Console.WriteLine();
}
}
}
// Star Square pattern in Javascript.
let n = prompt("Enter the number of rows: ");
for (let i = 1; i <= n; i++) {
for (let j = 1; j <= n; j++) {
document.write("*");
}
document.write("<br>");
}
1. input n, from the user
2. loop from i = 1 to i <= n
3. loop from j = 1 to j <= n
4. print a star (*)
5. output a newline character
6. end for
Comments
Oops!