Diamond Pattern || Numbers || Pattern || for loop || C Programming

This is a nested for loop program in which we are going to see how to print the above pattern of Diamond of Numbers, with the help of the C Programming language.




#include <stdio.h>

int main()
{
    int num;
    printf("Enter the number of Rows:\n");
    scanf("%d", &num);
    int i, j, k;
    for (i = 1; i <= num; i++)
    {
        for (j = num - 1; j >= i; j--)
        {
            printf(" ");
        }
        for (k = 1; k <= (2 * i - 1); k++)
        {
            printf("%d", i);
        }
        printf("\n");
    }

    int l, m, n;
    for (l = num - 1; l >= 1; l--)
    {
        for (m = num - 1; m >= l; m--)
        {
            printf(" ");
        }
        for (n = 1; n < (l * 2); n++)
        {
            printf("%d", l);
        }
        printf("\n");
    }

    return 0;
}


#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post