Arrow Pattern

188
0
Home C 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;
}
Hephzibai
WRITTEN BY

Hephzibai

Hephzibai is a driven third-year student at St. Joseph's Institute of Technology, specializing in Computer Science and Engineering. With a keen interest in data science and also in fullstack.
One of my greatest strengths lies in my programming skills, which I've honed through countless hours of practice and participation in coding challenges. Platforms like Skillrack, HackerRank, and others have been my playgrounds, where I've tackled a wide range of problems with creativity and determination.

Leave a Reply

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