Program to print Pyramid pattern using numbers

Program to print Pyramid pattern using numbers

10 May 2023

10 May 2023

Write a program to print Pyramid pattern using numbers



Description about the Program to print Pyramid pattern using numbers

 

Get the number of lines as the input and print row number in that many lines in a pyramid shape.

Input

4

Output

       1

     222

   33333

4444444

C  Program to print Pyramid pattern using numbers

#include <stdio.h>

int main() 

{

    int i, j, k, rows;

    printf("Enter number of rows: ");

    scanf("%d", &rows);

    for(i=1; i<=rows; i++)

    { 

        for(j=i; j<rows; j++)

                    printf(" ");

       for(k=1; k<=(2*i-1); k++)

                    printf("%d",i);

       printf("\n");

    }

    return 0;

}

C++ Program to print Pyramid pattern using numbers

#include <iostream>

using namespace std;

int main() 

{

    int i, j, k, rows;

    cout<<"Enter number of rows: ";

    cin>>rows;

    for(i=1; i<=rows; i++)

    { 

        for(j=i; j<rows; j++)

            cout<<" ";

       for(k=1; k<=(2*i-1); k++)

            cout<<i;

       cout<<"\n";

    }

    return 0;

}

Java Program to print Pyramid pattern using numbers

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter the number of rows: ");

int rows = sc.nextInt();

for(int i=1; i<=rows; i++)

    { 

        for(int j=i; j<rows; j++)

            System.out.print(" ");

       for(int k=1; k<=(2*i-1); k++)

            System.out.print(i);

       System.out.println("");

    }

}

}

Python Program to print Pyramid pattern using numbers

rows=int(input("Enter the number of rows: "))

for i in range(0,rows+1):

    for j in range(i,rows):

        print(" ",end="")

    for k in range(0,2*(i-1)+1):

        print(i,end="")

    print()


If you are from 2023 batch student, Join our Telegram group for placement preparation and coming placement drive updates : https://t.me/talentbattle2023


Related Articles

Ask Us Anything !