C Program To Print Square star Pattern

Ex: Write a C Program To Print Square star Pattern. How to write a C Program To Print Square star Pattern. C Program To Print Square star Pattern.


Input from user:
Enter number: 5

Expected output:
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *




   Step by step logic to print square star pattern:

1. First accept input(number) from user  which shows how many rows and column's do you want to print.

2. After that use one external for loop which will interate from 0 to no-1 and it shows rows in your square pattern:
for(i=0;i<no;i++)

3. Then use one another for loop inside the above for loop which prints the number of columns:
for(j=0;j<no;j++)

4. Inside the inner loop means inside the second for loop print * with one space like this:
printf("* ");

5.  After that use \n for new line(new row).





   Program to print sqaure star pattern:



#include<stdio.h>
void main()
{
int i,j,no;

printf("Enter the number:\n");
scanf("%d",&no);

for(i=0;i<no;i++)
{
for(j=0;j<no;j++)
{
printf("* ");
}
printf("\n");
}
}



Above Program show's the following output:

C Program To Print Square star Pattern




No comments:

Post a Comment

If you have any doubts, please discuss here...👇