Computer Science, asked by ns143568, 11 months ago

decode the logic of program If N= 3

then pattern will be :

10203010011012

**4050809

****607

If N= 4

then pattern will be:

1020304017018019020

**50607014015016

****809012013

******10011
and print the pattern

Answers

Answered by sailorking
26

import java.util.*;

class pro

{

 public static void main(String args[])

{

int c=0;int t=0;

System.out.println(“Enter the length”);

int n=sc.nextInt();

int res=(n*n) - 1;

for( int i=1;i<=n;i++)

{ t=res;

 for( int j=1;j<=n-(i-1);j++)

{ c++;

System.out.print(c);

}

for( int k=1;k<= n-(i-1);k++)

{

System.out.print(t);

t++;

}

res=res-(i+1);

System.out.println();

}

}

}

Answered by amitnrw
15

Answer:

There are N number of Rows

1st Row :  1,02....0N 0(N²+1)0(N²+2) ......... 0(N²+N)

2nd Row  **(1+N).....(N-1+N) 0(N²- (N - 2))....            0(N²-1) 0(N²)

.

.

Nth Row 2(N-1)times* (N(N+1)/2 0((N(N+1)/2 + 1)

Explanation:

If N= 3

then pattern will be :

10203010011012

**4050809

****607

If N= 4

then pattern will be:

1020304017018019020

**50607014015016

****809012013

******10011

LOGIC :

There are N number of Rows

1st Row :  1,02....0N 0(N²+1)0(N²+2) ......... 0(N²+N)

2nd Row  **(1+N).....(N-1+N) 0(N²- (N - 2))....            0(N²-1) 0(N²)

.

.

Nth Row 2(N-1)times* (N(N+1)/2 0((N(N+1)/2 + 1)

Similar questions