Learn about Square Pattern Program with Numbers 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.
Contents
Square Pattern Program with Numbers in C
Pattern:
1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5
Program:
#include<stdio.h>
int main()
{
int n;
printf("Enter the number of rows: ");
scanf("%d",&n);
for(int r=1; r<=n; r++)
{
for(int c=1; c<=n; c++)
{
printf("%3d",r);
}
printf("\n");
}
return 0;
}
Output:
Enter the number of rows: 5 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 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 2 in C
Pattern Program 1 in C