Menu Close

Seating layout according to the number of rows.

Laaysa with his friends going to the theatre for a movie.  The seating arrangement is triangular in size. 

Theatre staffs insisted the audience to sit in odd row if the seat number is odd and in even row if the seat number is even. But the instruction is very confusing for Laaysa and his friends.

So help them with the seating layout so that they can sit in correct seats.

Input: 
Single value representing the number of rows in the theatre.

Output: 
Print the layout based on the number of rows.
#include <stdio.h>
int main()
{
   int n;
  int i,j,k;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
   if(i%2==0){
   k=2;
   }
   else{
   k=1;
   }
   for(j=1;j<=i;j++){
   printf("%d ",k);
   k +=2;
   }
   printf("\n");
  }
return 0;}

INPUT_1:
7

OUTPUT:
1
2  4
1  3  5
2  4  6  8
1  3  5  7  9
2  4  6  8  10  12
1  3  5  7  9  11  13


INPUT_2:
11

OUTPUT:
1
2  4
1  3  5
2  4  6  8
1  3  5  7 9
2  4  6  8  10   12
1  3  5  7  9  11  13
2  4  6  8  10  12  14  16
1  3  5  7  9  11  13  15  17
2  4  6  8  10  12  14  16  18  20
1  3  5  7  9  11  13  15  17  19  21



Morae Q!