Computer Science, asked by simmi0903, 1 month ago

WRITE A PROGRAM TO PRINT THE GIVEN PATTERN. SO SCAM PLEASE..Only expert ans this question​

Attachments:

Answers

Answered by allysia
1

Using python:

Please refer to the attachment.

Partition:

I couldn't make a it all at once  so here's the partition data,

We're gonna make it quarterly,

The first portion is a triangle from left side such that bigger numbers are included as for example,

___1

__12

_123

1234

_ represents a space since the site doesn't preserves spaces.

I'm repeated this part for right half excluding 1 in the row such that the second quarter is,

___

1___

21__

321_

Combining them returns:

___1___

__121__

_12321_

1234321

Reversing the process again returns the second lower portion of this diamond.

Explanation:

The first for loop determines the number of rows will be there in the first top half.

The 2nd for loop determines the number of blank spaces in the diamond and you may see for yourself that it is when n=5 for the first row it should be 4 on each side and it reduces with each time the loop runs.

When n=5 and loop has run once(for first row ) the number of rows = 4

for second row it becomes 3 and so on.

The 3rd loop append the numbers, for first quarter and

the 4th loop makes the 2nd quarter of the diamond.

For the lower part, I reduced the limit n to n-1 after reversing the loop.

Attachments:
Answered by BrainlyProgrammer
3

This is a very easy Question, you just need to divide this great pattern into two halves

Part1:-

1

12 1

123 21

1234 321

12345 4321

Part2:-

1234 321

123 21

12 1

1

Note:-

The space(between the pattern) is added to show that each part is futher divided into two parts that is inside one loop we need to use 1 loop for printing space, 2nd loop for 1st part, 3rd loop for 2nd part of Part1 and Part 2.

Since it is not mentioned in which language we should solve this question, i am doing in JAVA Code.

Here comes the code

Java Code:-

package Coder;

public class DiamondPatt

{

public static void main (String ar [])

{

int i,j;

for(i=1;i<=5;i++)

{

for(j=5;j>i;j--)

{

System.out.print(" "); //This loop prints the spaces

}

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

{

System.out.print(j); //This loop prints 1..12..123 in different lines

}

for(j=(i-1);j>=1;j--)

{

System.out.print(j); //This loop prints 1 21 321....in different lines

}

System.out.println();

}

for(i=4;i>=1;i--)

{

for(j=5;j>i;j--)

{

System.out.print(" "); //This loop prints the spaces

}

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

{

System.out.print(j); //This loop prints 1..12..123 in different lines

}

for(j=(i-1);j>=1;j--)

{

System.out.print(j); //This loop prints 1..21..321 in different lines

}

System.out.println();

}

}

}

Learn more:-

  •  \sf \: https://brainly.in/question/33354968

Anonymous: You are genius in CS :D
BrainlyProgrammer: Thanks...Not a genius but a lazy coder....XD
Anonymous: : )
Similar questions