Program to print square star pattern

*****
*****
*****
*****
*****


Problem Statement:- Program to print a square star pattern.

Sample Input/Output:-


Sample Input First:5

Sample Output First: 

***** 
***** 
***** 
***** 
***** 

Sample Input Second: 4


Sample Output Second: 

****
****
****
****

Data requirement:-


  Input Data:- row_size


  Output Data:- *


  Additional Data:- in,out


Program in C

Here is the source code of the C Program to print a square star pattern.


Code:


#include<stdio.h>
int main()
{
  printf("Enter the row and column size:");

  int row_size,out,in;
  scanf("%d",&row_size);
  for(out=1;out<=row_size;out++)
  {
   for(in=1;in<=row_size;in++)
    printf("*");

        printf("\n");
  }
}

Input/Output:
Enter the row and column size:5
*****
*****
*****
*****
*****

Program in C++

Here is the source code of the C++ Program to print a square star pattern.


Code:


#include<iostream>
using namespace std;
int main()
{
  cout<<"Enter the row and column size:";
  int row_size,out,in,p;
  cin>>row_size;
  for(out=1;out<=row_size;out++)
  {
   for(in=1;in<=row_size;in++)
    cout<<"*";

        cout<<"\n";

  }
}

Input/Output:
Enter the row and column size:4
****
****
****
****

Program in Java

Here is the source code of the Java Program to print a square star pattern.


Code:


import java.util.Scanner;
public class p7 {

public static void main(String[] args) {

Scanner cs=new Scanner(System.in);
System.out.println("Enter the row and column size:");

  int row_size,out,in;

  row_size=cs.nextInt();
  for(out=1;out<=row_size;out++)
  {
   for(in=1;in<=row_size;in++)
    System.out.print("*");

        System.out.println();

  }
cs.close();
}
}

Input/Output:
Enter the row and column size:
3
***
***
***

Program in Python

Here is the source code of the Python Program to print a square star pattern.


Code:


print("Enter the row and column size:");
row_size=int(input())
for out in range(0,row_size):
    for i in range(0,row_size):
        print("*")
    print("\r")

Input/Output:
Enter the row and column size:
5
***** 
***** 
***** 
***** 
***** 


Post a Comment

0 Comments