Ex: Write a C program to print square number pattern 2. How to write a C program to print square number pattern 2. C program to print square number pattern 2.
Input from user:
Enter the number: 5
Expected output:
11111
22222
33333
44444
55555
Given pattern is same as previous square number pattern:
11111
11111
11111
11111
11111
Difference is:
In this pattern we only need to replace the 1 with value of i .
Program:
#include<stdio.h>
void main()
{
int no;
int i,j;
printf("Enter the number:");
scanf("%d",&no);
/*Loop to print rows */
for(i=1;i<=no;i++)
{
/*Loop to print columns */
for(j=1;j<=no;j++)
{
/*print value of i*/
printf("%d",i);
}
/*for new line*/
printf("\n");
}
}
Above program shows the following output: