Printing Pattern Using Loops || Hacker Rank

 Question 10 || Hacker Rank

Printing Pattern Using Loops || Hacker Rank


Printing Pattern Using Loops


Print an example of numbers from to as displayed underneath. Every one of the numbers is isolated by a solitary space.

                     4 4 4 4 4 4 4

                            4 3 3 3 3 3 4

                            4 3 2 2 2 3 4

                            4 3 2 1 2 3 4

                            4 3 2 2 2 3 4

                            4 3 3 3 3 3 4

                            4 4 4 4 4 4 4


Input Organization

The information will contain a solitary whole number .

 

Test Information 0

2

Test Result 0

2 2 2

2 1 2

2 2 2

Test Information 1

5

Test Result 1

5 5 5 5 5 5 5 5 5

5 4 4 4 4 4 4 4 5

5 4 3 3 3 3 3 4 5

5 4 3 2 2 2 3 4 5

5 4 3 2 1 2 3 4 5

5 4 3 2 2 2 3 4 5

5 4 3 3 3 3 3 4 5

5 4 4 4 4 4 4 4 5

5 5 5 5 5 5 5 5 5

Test Information 2

7

Test Result 2

7 7 7 7 7 7 7 7 7 7 7 7 7

7 6 6 6 6 6 6 6 6 6 6 6 7

7 6 5 5 5 5 5 5 5 5 5 6 7

7 6 5 4 4 4 4 4 4 4 5 6 7

7 6 5 4 3 3 3 3 3 4 5 6 7

7 6 5 4 3 2 2 2 3 4 5 6 7

7 6 5 4 3 2 1 2 3 4 5 6 7

7 6 5 4 3 2 2 2 3 4 5 6 7

7 6 5 4 3 3 3 3 3 4 5 6 7

7 6 5 4 4 4 4 4 4 4 5 6 7

7 6 5 5 5 5 5 5 5 5 5 6 7

7 6 6 6 6 6 6 6 6 6 6 6 7

7 7 7 7 7 7 7 7 7 7 7 7 7


#include<stdio.h>

int main()
{
    int n;
    scanf("%d",&n);

    int size=2*n - 1;
    for(int i=0;i<size;i++)
{
    for(int j=0;j<size;j++)
{
    int min = i < j ? i : j;
    min = min < size - i ? min : size - i - 1;
    min = min < size - j ? min : size - j - 1;
    printf("%d ", n - min);
}
    printf("\n");
}

return 0;
}

Output


Printing Pattern Using Loops




Post a Comment

0 Comments