\(\begin{array}{cccc}1&2&3&4\\5&6&7&8\\9&10&11&12\\13&14&15&16\end{array}\)
Write a program that reads a number (number of lines equal to the number of columns) and displays the above pattern.
Difficulty level
This exercise is mostly suitable for students
#include<stdio.h>
#include<conio.h>
void main()
{
int N, i, j, counter;
do{
printf("Enter N: ");
scanf("%d",&N);
}while(N<=0);
counter = 1;
for(i=1; i<=N; i++)
{
for(j=1; j<=N; j++, counter++)
printf("%4d", counter);
printf("\n");
}
getch();
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Sum of the lower triangular matrix