1.
Introduction
2.
Half Pyramid in C
3.
Half Pyramid in C++
4.
Half Pyramid in Java
5.
Half Pyramid in Python
6.
6.1.
What is a loop in programming?
6.2.
What are the different types of loops?
6.3.
Is there no for loop in Python?
7.
Conclusion
Last Updated: Mar 27, 2024
Medium

# Half Pyramid

0 upvote

## Introduction

Half pyramid is a pattern, and it is in a triangle shape. In this blog, we will implement half pyramid of numbers using programming languages C, C++, Java, and Python. The pattern will be made with non-repetitive numbers. But before moving on to the blog, first clearance of basic loops is essential. You can refer to loops in C/C++loops in Java, and loops in Python.

## Half Pyramid in C

Problem Statement: Write a program to print a half pyramid where numbers are non-repetitive in C.

Solution:

``````#include <stdio.h>
int main()
{
printf("Size of row : 5\n");
int i,j;
for(i=1;i<=row;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
}``````

Output:

``````Size of row :5
1
12
123
1234
12345``````

## Half Pyramid in C++

Problem Statement: Write a program to print a half pyramid where numbers are non-repetitive in C++.

Solution:

``````#include <iostream>
using namespace std;
int main()
{
cout<<"Enter the size of row : 5\n";
for(int i=1;i<=row;i++)
{
for(int j=1;j<=i;j++)
{
cout<<j;
}
cout<<"\n";
}
}``````

Output:

``````Size of row :5
1
12
123
1234
12345``````

## Half Pyramid in Java

Problem Statement: Write a program to print half pyramid where numbers are non-repetitive in Java.

Solution:

``````public class pattern {

public static void main(String[] args) {
System.out.println("Size of row : 5");

for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(j);
}
System.out.println();
}
}
}``````

Output :

``````Size of row :5
1
12
123
1234
12345``````

Must Read What are Loops in Java.

## Half Pyramid in Python

Problem Statement: Write a program to print a half pyramid where numbers are non-repetitive in Python.

Solution:

``````print(â€śSize of row :5â€ť)
for i in range(1,6):
for j in range(1,i+1,+1):
print(j,end="")
print("\r")``````

Output :

``````Size of row :5
1
12
123
1234
12345``````

### What is a loop in programming?

Loops are sequences of program lines that need to be repeated until some condition is fulfilled.

### What are the different types of loops?

There are two types of loops: entry control and exit control loops.

### Is there no for loop in Python?

There is for in loop in Python instead of for loop.

## Conclusion

In this article, we have extensively discussed the implementation of a half pyramid with non-repetitive numbers in different programming languages.