Ex: Write a C program to print given square number pattern. How to write a C program to print given square number pattern. C program to print given square number pattern.
Input from user:
Enter the number: 5
Expected output:
11111
11111
11111
11111
11111
Step by step logic of the given program:
To print this pattern, first you need understand square star pattern:
1. Accept input number from user declare variable say no.
2. Run outer for loop from 1 to no to print number of rows.
3. Run inner for loop from 1 to no to print number of columns.
4. Inside the inner loop print 1.
5. For next row print new line \n.
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++)
{
/*you can add any number here to print their pattern*/
printf("1");
}
/*for new line*/
printf("\n");
}
}
Above program shows the following output:
No comments:
Post a Comment
If you have any doubts, please discuss here...👇