Program to Print the Double Pyramid Star Pattern

******

*****

****

***

**

*

**

***

****

*****

******

Problem statement:- Program to Print the Double Pyramid Star Pattern.

 Data requirement:-

   Input Data:- row_size

  Output Data:- *

  Additional Data:-in or inn(for python), out

Program in C

Here is the source code of the C program to Print the Double Pyramid Star Pattern.

Code:

#include<stdio.h>
#include<math.h>
int main()
{
    int out,in;
    printf("Enter the row size:");
    int row_size;
    scanf("%d",&row_size);
   for(out=row_size;out>=-row_size;out--)
    {
     for(in=0;in<=abs(out);in++)
     {
    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 Double Pyramid Star Pattern.

Code:

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int out,in;
    cout<<"Enter the row size:";
    int row_size;
    cin>>row_size;
   for(out=row_size;out>=-row_size;out--)
    {
     for(in=0;in<=abs(out);in++)
     {
    cout<<"*";
         }
    cout<<"\n";
}}

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

Program in Java

Here is the source code of the Java Program to Print the Double Pyramid Star Pattern.

Code:

import java.util.Scanner;
public class StarPattern16 {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
        int out,in;
    System.out.println("Enter the row size:");
    int row_size=cs.nextInt();
    for(out=row_size;out>=-row_size;out--)
    {
     for(in=0;in<=Math.abs(out);in++)
     {
    System.out.printf("*");
     }
    System.out.println();
    }
    cs.close();
}
}

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

Program in Python

Here is the source code of the Python Program to Print the Double Pyramid Star Pattern.

Code:

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

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

Post a Comment

0 Comments