Â
In this, we are going to see a program in which we will be printing a Recurring Square Number pattern as shown in above image in C Programming Language.
/*Number Pattern - (Shifting)
1 2 3 4 5
2 3 4 5 1
3 4 5 2 1
4 5 3 2 1
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 <= n; col++)
{
if (col != (row + 1))
{
//add space
printf(" ");
}
printf("%d", col);
}
for (int col = row; col > 0; col--)
{
if (col != 0)
{
//add space
printf(" ");
}
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