0
2.6kviews
Write a program to display following pattern.

enter image description here

Subject : Structured Programming Approach

Title : Control Structures

Difficulty : Medium

1 Answer
0
81views

Program:

#include <stdio.h>

#include<conio.h>

void main( )

{

    int i, s, r, k=0, c=0, j=0;

    printf(“Enter the number of rows : “);

    scanf(“%d”, &r);

    for( i=1 ; i<=r ; i++ )

    {

        for( s=1 ; s<=r-i ; s++ )

        {

            prinf(“ ”);

            c++;

        }

        while( k != 2*i-1 )

        {

            if(c<=r-1)

            {

                printf(“%d”,(i+k));

                c++;

            }

            else

            {

                j++;

                printf(“%d”,(i+k-2*j));

            }

            ++k;

        }

        j=c=k=0;

        printf(“\n”);

    }

    getch( );

}

Output:

Enter the number of rows : 5

enter image description here

Please log in to add an answer.