Skip to content
Home » Number square Pattern Program in C

Number square Pattern Program in C

Learn about Number square Pattern Program in C in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Number square Pattern Program in C

Pattern:

   1   1   1   1   1
   1   1   1   2   2
   1   1   3   3   3
   1   4   4   4   4
   5   5   5   5   5

Program:

#include<stdio.h>
int main()
{
  int n,r,c;

  printf("Enter number of rows: ");
  scanf("%d",&n);

  for(r=1; r<=n; r++)
  {
    for(c=1; c<=n; c++)
    {
      if(c <= n-r) printf("%4d",1);
      else printf("%4d",r);
    }

    printf("\n");
  } 
  return 0;
}

Output:

Enter number of rows: 5
   1   1   1   1   1
   1   1   1   2   2
   1   1   3   3   3
   1   4   4   4   4
   5   5   5   5   5

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
Pattern Program 8 in C
Pattern Program 7 in C