You're online now.

Hurray! you are online now.

Star Square Pattern

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>");
    }
    

Algorithm to print Star Square Pattern

  1. Get the number of rows ‘n’ from the user.
  2. Loop from ‘1’ to ‘n’ to iterate over the rows.
  3. For each row, loop from ‘1’ to ‘n’ to iterate over the columns.
  4. print the * star.
  5. After iterate the nested loop print the next line.
  6. Exit.

Pseudocode of star square pattern

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
    
🖤 0
Buy me coffee ☕

Comments

Oops!

No comments here...