Half Diamond Star Pattern
Half Diamond Star Pattern consist of a single triangular pattern that resembles half of a diamond shape. The stars are arranged in that way each row has a decreasing number of stars as it moves away from the center.
Output
Enter the number of rows: 5
*
**
***
****
*****
****
***
**
*
Free E-Books
Codes of Half Diamond Star Pattern
#include <stdio.h> int main() { int rows, i, j; printf("Enter the number of rows: "); scanf("%d", &rows); // Upper half of the diamond for (i = 1; i <= rows; i++) { for (j = 1; j <= i; j++) { printf("*"); } printf("\n"); } // Lower half of the diamond for (i = rows - 1; i >= 1; i--) { for (j = 1; j <= i; j++) { printf("*"); } printf("\n"); } return 0; }
Codes Explanation
- This program shows the prompts to user for enter the number of rows for the half diamond.
- After that it divides the half diamond into two parts: the upper half and the lower half.
- For each part, it iterates through each row using a
for
loop. Within each row, it prints stars using another nestedfor
loop. - The number of stars in each row follows a pattern: increasing from 1 to the middle row, then decreasing back to 1.