Program to print the Solid Inverted Half Diamond Star Pattern

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


Problem statement:-   Program to print the Solid Inverted Half Diamond Star Pattern.

 Data requirement:-

   Input Data:- row_size

  Output Data:- *

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

Program in C

Here is the source code of the C  Program to print the Solid Inverted Half Diamond Star Pattern.

Code:

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

Code:

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    cout<<"Enter the row size:";
    int row_size;
    cin>>row_size;
    int in,out,p;
    for(out=row_size;out>=-row_size;out--)
    {
        for(in=1;in<=abs(out);in++)
             cout<<" ";
            for(p=row_size;p>=abs(out);p--)
                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 Solid Inverted Half Diamond Star Pattern.

Code:

import java.util.Scanner;
public class StarPattern11 {

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=row_size;out>=-row_size;out--)
    {
     for(int in=1;in<=Math.abs(out);in++)
      System.out.printf(" ");
    for(int p=row_size;p>=Math.abs(out);p--)
     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  Program to print the Solid Inverted Half Diamond Star Pattern.

Code:

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

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


More:-

C/C++/Java/Python Practice Question 

Post a Comment

0 Comments