How to print given star pattern.
What we be the general solution of given star pattern in C programming language.
This programming is executed on Dev C++ editor. You may run this programming program on any C or C++ editor.
1st way for Star pattern programming.
#include<stdio.h>
#include<conio.h>
int main()
{
int row, col, n; // data type deceleration.
printf("Enter The number of row");
scanf("%d",&n); // taking input for the number of rows.
for(row=1;row<=n;row++) //for rows.
{
for(col=1;col<=row;col++) // for columns.
{
printf("*"); //printing the star in for given pattern.
}
printf("\n"); // for new line.
}
return 0;
}
Output:-
Enter The number of row 5
*
**
***
****
*****
This is general solution of given pattern. In this I have entered 5 for number of rows. It's your choice how much you enter the number of rows the pattern will be same with your number of rows.
There is also another solution for this question but it is not the best way because it is not more effective like 1st one. The best programming is the one which consume less memory and less time for execution. So the next programming for only knowledge purpose because it consume more time to execute.
2nd way for Star pattern programming.
#include<stdio.h>
#include<conio.h>
int main()
{
int row, col, n; // data type deceleration.
printf("Enter The number of row");
scanf("%d",&n); // taking input for the number of rows.
for(row=1;row<=n;row++) //for rows.
{
for(col=1;col<=n;col++) // for columns
{
if(col<=row) //condition for printing start.
{
printf("*");
}
else // for free space.
{
printf(" ");
}
}
printf("\n"); //new line.
}
getch();
return 0;
}
Output:-
Enter The number of row 5
*
**
***
****
*****
This programming is not the best solution for this start pattern because this consume more time and more space. So I will always prefer the 1st solution for this star pattern.
If you face any problem then you can comment in comment section or go to my YouTube Video and watch it.
👌👌👌👌
ReplyDeleteSuperb
ReplyDeleteActually very useful,it was simple and easy to understand
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteUseful content.. 👌
ReplyDeleteBdhiya
ReplyDeleteLong live mele pliye lambu
ReplyDeleteKeep it up bro .
ReplyDeletePractice makes perfect 🎉💐🥇