\(\begin{array}{cccc}1&2&3&4\\2&1&2&3\\3&2&1&2\\4&3&2&1\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;
do{
printf("Enter N: ");
scanf("%d",&N);
}while(N<=0);
for(i=1; i<=N; i++)
{
for(j=i; j>1; j--)
printf("%4d", j);
for(j=1; j<=N-i+1; j++)
printf("%4d", j);
printf("\n");
}
getch();
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Alexandrine multiplication