Program to print the Full Pyramid Number Pattern


        1
      123
    12345
  1234567
123456789


Problem Statement:-  Program to print the Full Pyramid Number Pattern.

Sample Input/Output:-


Sample Input First:5

Sample Output First: 

        1
      123
    12345
  1234567
123456789

Sample Input Second: 4


Sample Output Second: 

        1
      123
    12345
  1234567

Data requirement:-


   Input Data:- row_size

  Output Data:- in2

  Additional Data:-in1, out, np

Program in C
  
Here is the source code of the C Program to print the Full Pyramid Number Pattern.

Code:


#include <stdio.h>
int main()
{
  printf("Enter the row size:");
  int row_size,out,in1,in2;
  int np=1;
  scanf("%d",&row_size);
  for(out=0;out<row_size;out++)
       {
       for(in1=row_size-1;in1>out;in1--)
       {
            printf(" ");
       }
       for(in2=1;in2<=np;in2++)
       {
           printf("%d",in2);
       }
       np+=2;
       printf("\n");
       }
}

Input/Output:
Enter the row size:5
        1
      123
    12345
  1234567
123456789

Program in C++
  
Here is the source code of the C++ Program to print the Full Pyramid Number Pattern.

Code:

#include <iostream>
using namespace std;
int main()
{
  cout<<"Enter the row size:";
  int row_size,out,in1,in2;
  int np=1;
  cin>>row_size;
  for(out=0;out<row_size;out++)
       {
       for(in1=row_size-1;in1>out;in1--)
       {
            cout<<" ";
       }
       for(in2=1;in2<=np;in2++)
       {
           cout<<in2;
       }
       np+=2;
       cout<<"\n";
       }
}

Input/Output:
Enter the row size:4
         1
      123
    12345
  1234567

Program in Java
  
Here is the source code of the Java Program to print the Full Pyramid Number Pattern.

Code:


import java.util.Scanner;
public class P33 {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
        System.out.println("Enter the row size:");

        int row_size,out,in1,in2;
        int np=1;
        row_size=cs.nextInt();
 
       for(out=0;out<row_size;out++)
       {
       for(in1=row_size-1;in1>out;in1--)
       {
           System.out.print(" ");
       }
       for(in2=1;in2<=np;in2++)
       {
           System.out.print(in2);
       }
       np+=2;
       System.out.println();
       }
     cs.close();
}
}

Input/Output:

Enter the row size:
3
         1
      123
    12345

Program in Python
  
Here is the source code of the Python Program to print the Full Pyramid Number Pattern.

Code:

row_size=int(input("Enter the row size:"))
np=1
for out in range(0,row_size):
    for in1 in range(row_size-1,out,-1):
        print(" ",end="")
    for in2 in range(1, np+1):
        print(in2,end="")
    np+=2
    print("\r")

Input/Output:
Enter the row size:4
        1
      123
    12345
  1234567



Post a Comment

0 Comments