Computer Science, asked by pavithran2, 1 year ago

you are given an integer N,print N+1 lines in a following manner

case 1: N=3 then the pattern would be
333 \\ 313 \\ 323 \\ 333
case 2: N=4 then the pattern would be
44444 \\ 44144 \\ 44244 \\ 44344 \\ 44444

Answers

Answered by beliber542
3
NN
N1
N2
N3
HERE INTEGER N+1
Answered by MavisRee
2

The program in JAVA is written below :

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter value of n : ");

int n = sc.nextInt( );

int row = 0;

int column = 0;  

 if(n%2 == 0) {

row = n + 1 ;

column = n + 1 ;

     }

else {

row = n+1;

column = n;

}

int arr [ ] [ ] = new int [row] [column] ;

 int count = 1 ;

 int half = n / 2 ;

 for ( int i = 0 ; i < row ; i++ ) {

   for ( int j = 0 ; j<column ; j++) {

if ( ( i > 0 && i < row ) && j == half) {

    arr[ i ] [ j ] = count;

     count++;

}

else {

   arr [ i ] [ j ] = n;

}

}

}

for( int i = 0; i < row ; i++) {

for( int j=0 ; j < column ; j++) {

System.out.print ( arr [ i ] [ j ] );

}

System . out . println( );

}

sc.close( );

}

Similar questions