C

Layered L. Pattern

115
0
Home C Layered L. Pattern

The program must accept an integer N as the input. The program must print the desired pattern as shown in the Example Input/Output section.

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

Input Format:
The first line contains N.

Output Format:
The first N lines contain the desired pattern as shown in the Example Input/Outputsection.

Example Input/Output 1:
Input:

5
Output:
1
12
123
1222
11111

Example Input/Output 2:
Input:

10
Output
1
12
123
1234
12345
123455
1234444
12333333
122222222
1111111111

#include<stdio.h> 
#include<stdlib.h>

int main()
{
	int n;
	scanf("%d",&n); 
	if(n%2==0)
	{
		for (int i=1;i<=(n/2);i++)
		{
			for(int j=1;j<=i;j++) 
				printf("%d ",j); 
			printf("\n");
		}
		int u=n/2;
		for (int i=0;i<u;i++)
		{
			int j;
			for (j=1;j<=u-i;j++) 
				printf("%d ",J);
			j--;
			for (int k=0;k<=i;k++) 
				printf("%d ",j); 
			printf("\n");
	}
	else
	{
		for(int i=1;i<(n/2)+2;i++)
		{
			for(int j=1;j<i;j++) 
				printf("%d ",j); 
			printf("\n");
		}
		for (int i=0;i<u;i++)
		{
			int j;
			for (j=1;j<=u-i;j++) 
				printf("%d ",J);
			j--;
			for (int k=0;k<=i;k++) 
				printf("%d ",j); 
			printf("\n");
		}
	}
}
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 *