Program to Print Half Diamond number pattern in C

[1937 views]




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 <stdio.h> 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
                 






Comments










Search Anything:

Sponsored Deals ends in



Technical Quizzes Specially For You:

Search Tags

    Half Diamond Pattern code in C

    C program for printing Half Diamond pattern with input from user