Program to print the Inverted Half Pyramid Number Pattern

Write a C Program to Program to print the Inverted Half Pyramid Number Pattern.

12345
  1234
    123
      12
        1

Problem statement:-  Program to print the Inverted Half Pyramid Number Pattern

 Data requirement:-

   Input Data:- row_size

  Output Data:- in2

  Additional Data:-in1, out

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


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

Input/Output:
Enter the row size:5
12345
  1234
    123
      12
        1

Write a C++ Program to print the Inverted Half Pyramid Number Pattern.

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

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


Input/Output:
Enter the row size:6
123456
  12345
    1234
      123
        12
          1

Write a Java Program to print the Inverted Half Pyramid Number Pattern.

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


import java.util.Scanner;
public class P30 {

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;
        row_size=cs.nextInt();
 
        for(out=row_size;out>=1;out--)
{
    for(in1=row_size-1;in1>=out;in1--)
    {
        System.out.print(" ");
    }
    for(in2=1;in2<=out;in2++)
    {
         System.out.print(in2);
    }
    System.out.println();
  }
     cs.close();
}
}


Input/Output:
Enter the row size:
4
1234
  123
    12
      1

Write a Python Program to print the Inverted Half Pyramid Number Pattern.

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


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


Input/Output:
Enter the row size:3
123
  12
    1

Post a Comment

0 Comments