Â
In this, we are going to see a program in which we will be printing a Diagonal / slant Square Number pattern as shown in above image in C Programming Language.
/*Number Pattern - (Diagonal/slant)
1 2 3 4 5
2 1 2 3 4
3 2 1 2 3
4 3 2 1 2
5 4 3 2 1*/
#include <stdio.h>
int main()
{
int n;
printf("Enter no. of rows/columns: ");
scanf("%d", &n);
for (int row = 0; row < n; row++)
{
for (int col = row + 1; col > 0; col--)
{
if (col != (row + 1))
{
//add space
printf(" ");
}
printf("%d", col);
}
for (int col = 2; col <= (n - row); col++)
{
printf(" %d", col);
}
printf("\n");
}
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP