Arrow Pattern

Write a program that generates a pattern based on the input value n following a specific format.

Input Format:
The input is a single integer n, where n represents the number of rows in the pattern.

Constraints:
The input value n is a positive integer greater than zero.

Output Format:
The program should output the generated pattern as a series of numbers and zeros, following the given format.

Example Input/Output 1:
Input:
5
Output:
1
2 2
3 0 3
4 0 0 4
5 0 0 0 5
4 0 0 4
3 0 3
2 2
1

Example Input/Output 1:
Input:
3

Output:
1
2 2
3 0 3
2 2
1

#include <stdio.h>

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

    for(int i=1;i<=n;i++)
    {
        printf("%d ",i);

        for(int j=1;j<i-1;j++)
            printf("0 ");

        if(i>1)
            printf("%d ",i);

        printf("n");
    }

    for(int i=n-1;i>=1;i--)
    {
        printf("%d ",i);

        for(int j=1;j<i-1;j++)
            printf("0 ");

        if(i>1)
            printf("%d ",i);

        printf("n");
    }
    return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

More posts. You may also be interested in.