## Q. Write a program to print half pyramid pattern using stars.

Half Pyramid Example:-

```Half Pyramid Star Pattern
*
* *
* * *
* * * *
* * * * *
* * * * * *
```

# Half Pyramid Program

• C
• C++
• Java
• Python
• ```#include<stdio.h>
int main() {
int i, j, rows;
printf("Enter number of rows: ");
scanf("%d", &rows);
for (i=1; i<=rows; ++i) {
for (j=1; j<=i; ++j)
{ printf("* "); }
printf("\n");
}
return 0;
}
```
```#include <iostream>
using namespace std;
int main()
{
int rows;
cout << "Enter number of rows: ";
cin >> rows;
for(int i = 1; i <= rows; ++i)
{
for(int j = 1; j <= i; ++j)
{
cout << "* ";
}
cout << "\n";
}
return 0;
}```
```import java.util.*;
public class LFC {
public static void main(String[] args) {
int rows;
System.out.println("Enter number of rows: ");
Scanner sc = new Scanner(System.in);
rows = sc.nextInt();
for(int i = 1; i <= rows; ++i) {
for(int j = 1; j <= i; ++j) {
System.out.print("* ");
}
System.out.println();
}
}
}
```
```def halfpy(n):
for i in range(0, n):
for j in range(0, i+1):
# printing stars
print("* ",end="")
# ending line after each row
print("\r")
# Driver Code
print("Enter number of rows: ")
n = int(input())
halfpy(n)
```
```#include<stdio.h>
int main() {
int i, j, rows;
printf("Enter number of rows: ");
scanf("%d", &rows);
for (i=1; i<=rows; ++i) {
for (j=1; j<=i; ++j)
{ printf("* "); }
printf("\n");
}
return 0;
}
```

#### Output

```Enter number of rows: 5
*
* *
* * *
* * * *
* * * * *
```

## Recommended Programs

Program to print half inverted pyramid pattern.
Program to print lower triangular matrix.