Computer Science, asked by Arjeet1990, 8 hours ago

Consider the following 4×4 pattern: 1 2 4 7 3 5 8 11 6 9 12 14 10 13 15 16 You are given an integer N. Print the N×N pattern of the same kind (containing integers 1 through N2).

Answers

Answered by dharmendra20208039
0

Answer:

Explanation:

#include <stdio.h>

int main()

{  

 int n, p = 1, a[100][100] j, m, k, r;

 scanf("%d", &r);

 for (j = 1; j <= r; j++) {

   m = 0;

   n = j;

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

     a[m++][--n] = p++;

 }

 for (j = 1; j <= r-1; j++) {

   m = j;

   n = r-1;

   for (k = 1; k<= r-j; k++)

     a[m++][n--] = p++;

 }

 for (j = 0; j <= r-1; j++) {

   for (k = 0; k <= r-1; k++)

     printf("%d ", a[j][k]);

   printf("\n");

 }

 return 0;

}

Similar questions