Program to print square pattern of numbers

12345
12345
12345
12345
12345


Problem Statement:- Program to print a square pattern of numbers.

Sample Input/Output:-


Sample Input First:5

Sample Output First: 

12345
12345
12345
12345
12345

Sample Input Second: 6


Sample Output Second: 

123456
123456
123456
123456
123456
123456

Data requirement:-


  Input Data:- row_size


  Output Data:-in


  Additional Data:-out


Program in C

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


Code:


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

  int row_size,out,in,p;

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

        printf("\n");

  }
}

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

Program in C++

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


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<<in;

        cout<<"\n";

  }
}

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


Program in Java

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


Code:


import java.util.Scanner;
public class p9 {

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(in);

        System.out.println();

  }
cs.close();
}
}

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

Program in Python

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


Code:


print("Enter the row and column size:");

row_size=int(input())
for out in range(1,row_size+1):
    for i in range(1,row_size+1):
        print(i,end="")
    print("\r")


Input/Output:
Enter the row and column size:
6
123456
123456
123456
123456
123456
123456


Post a Comment

0 Comments