Inverse Two Triangle Pattern

Inverse Two Triangle Pattern

Problem:

Fill in the missing lines of code to implement the method (function) printPattern(int N) so that the method prints the pattern given in the Example Input/Output section. 

Boundary Condition(s): 1 <= N <= 1000 

Example Input/Output 1: 

Input: 

Output: 

54321

4321 

321 

21 

12 

123 

1234 

12345

Example Input/Output 2: 

Input: 

Output: 

7654321 

654321 

54321 

4321 

321 

21 

12 

123 

1234 

12345 

123456 

1234567

Program:

void printPattern(int N)

{

    for(int i = N; i>0; i--)

    {

        for(int j=i;j>0;j--)

        {

            printf("%d",j);

        }

        printf("\n");

    }

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

    {

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

        {

            printf("%d",j);

        }

        printf("\n");

    }

}

Comments

Popular posts from this blog

Pronic Integers in N - InfyTQ question

Count Strong Points - Accenture

Letters at position of multiples of a number