Showing posts with label Printing Pattern Using Loops Hacker Rank Solution in C. Show all posts
Showing posts with label Printing Pattern Using Loops Hacker Rank Solution in C. Show all posts

Tuesday, 15 December 2020

Printing Pattern Using Loops Hacker Rank Solution in C

https://www.hackerrank.com/challenges/printing-pattern-2 

Solution

#include <stdio.h>

int main() 

{

    int n,d,min;

    scanf("%d", &n);

  d=2*n-1;

    for(int i=1;i<=d;i++)

    {

        for(int j=1;j<=d;j++)

        {

            if(i<j)

                min=i-1;

            else

                min=j-1;

            if(min>d-j)

                min=d-j;

            if(min>d-i)

                min=d-i;

            printf("%d ",n-min);

        }

        printf("\n");

    }

    return 0;

}