Plz answer fast I need answer only using Nested for loop
Answers
Program:
Please consider the attachment.
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();
}
}
}