Program to print the Half Pyramid Number Pattern

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

1
22
333
4444
55555

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

 Data requirement:-

   Input Data:- row_size

  Output Data:- out

  Additional Data:-in or i(In Python)

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


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

    for(in=row_size;in>=out;in--)
    {
         printf("%d",out);
    }
    printf("\n");
}
}


Input/Output:
Enter the row size:5
11111
2222
333
44
5


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

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


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

    for(in=row_size;in>=out;in--)
    {
         cout<<out;
    }
    cout<<"\n";
}
}


Input/Output:
Enter the row size:3
111
22
3

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

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


import java.util.Scanner;
public class P29 {

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

        int row_size,out,in;
        row_size=cs.nextInt();
 
        for(out=1;out<=row_size;out++)
{
    for(in=row_size;in>=out;in--)
    {
        System.out.print(out);
    }
    System.out.println();
  }
     cs.close();

}
}



Input/Output:
Enter the row size:
6
111111
22222
3333
444
55
6

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

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


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

Input/Output:
Enter the row size:4
1111
222
33
4

Post a Comment

0 Comments