In this article, we will learn how to print Half Diamond Pattern using C programming language. You should have good understanding of "for loop" to write or understanding this algorithm.
Half Diamond Program in C:
#include
int main()
{
int i, j, noOfRows;
printf("Enter the number of rows: ");
scanf("%d", &noOfRows);
for (i = 1; i <= noOfRows; i++)
{
for (j = 1; j <= i; j++)
printf("%d ", j);
printf("\n");
}
for (i = noOfRows - 1; i >= 1; i--)
{
for (j = 1; j <= i; j++)
printf("%d ", j);
printf("\n");
}
return 0;
}
Output:
Enter the number of rows: 5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1