Display the Full Pyramid Star Pattern

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

Problem Statement:- Program to Print the Full Pyramid 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, p


Program in C

Here is the source code of the C Program to Display the Full Pyramid Star Pattern.


Code:


#include <stdio.h>
int main()
{
  printf("Enter the row size:");
  int row_sizeoutinp;
  scanf("%d", &row_size);
  for (out = 1out <= row_sizeout++)
  {
    for (in = row_size - 1in >= outin--)
      printf(" ");

    for (p = 1p <= outp++)
      printf("* ");

    printf("\n");
  }
}


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

Program in C++

Here is the source code of the C++ Program to Print the Full Pyramid Star Pattern.


Code:


#include <iostream>
using namespace std;
int main()
{
    cout << "Enter the row size:";
    int row_sizeoutinp;
    cin >> row_size;
    for (out = 1out <= row_sizeout++)
    {
        for (in = row_size - 1in >= outin--)
            cout << " ";
        for (p = 1p <= outp++)
            cout << "* ";
        cout << "\n";
    }
}


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

Program in Java

Here is the source code of the Java Program to Display the Full Pyramid Star Pattern.


Code:


import java.util.Scanner;

public class FullPyramidStarPattern {

    public static void main(String[] args) {
        Scanner cs = new Scanner(System.in);

        System.out.println("Enter the row size:");
        int row_size = cs.nextInt();

        for (int out = 1out <= row_sizeout++) {
            for (int in = row_size - 1in >= out;in--)
                System.out.printf(" ");
            for (int p = 1p <= outp++)
                System.out.print("* ");
            System.out.println();
        }
        cs.close();
    }
}


Input/Output:
Enter the row size:
6
     *   
    * *  
   * * * 
  * * * *
 * * * * *
* * * * * *

Program in Python

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


Code:


row_size = int(input("Enter the row size:"))
for out in range(row_size+1):
    for j in range(row_size-out):
        print(" "end="")
    for p in range(out+1):
        print("* "end="")
    print("\r")


Input/Output:
Enter the row size:7
       *        
      * *       
     * * *      
    * * * *     
   * * * * *    
  * * * * * *   
 * * * * * * *  
* * * * * * * * 





Post a Comment

0 Comments