How to Print Given Star Pattern
What will be the general solution of given star patter in C programming language.
This program is executed on Dev C++ editor. You may use any other editor the program will be same. If you face any problem then comment.
1st way
#include<stdio.h>
#include<conio.h>
int main()
{
int row ,col, n; //Data type declaration
printf("Enter the number of rows");
scanf("%d",&n); // Taking user input for number of rows
for(row=1;row<=n;row++) // For number of rows
{
for(col=n;col>=row;col--) //For number of columns
{
printf("*"); //Printing the star pattern
}
printf("\n"); // for new lines.
}
getch();
return 0;
}
Output
Enter the number of rows 5
*****
****
***
**
*
2nd way
#include<stdio.h>
#include<conio.h>
int main()
{
int row, col, n; //Data type declaration
printf("Enter The number of row");
scanf("%d",&n); // Taking user input for number of rows
for(row=1;row<=n;row++) // For number of rows
{
for(col=n;col>=1;col--) // For columns
{
if(col>=row) //Condition for printing star
{
printf("*");
}
else // For free space
{
printf(" ");
}
}
printf("\n"); // For new line
}
getch();
return 0;
}
Output
Enter The number of row 5
*****
****
***
**
*
This programming is general solution. In this both programming I have entered 5 as number of rows. It is up to you how much you entered the number of rows. If you entered 12 then it will print the star pattern of 12 rows. And I have provided two type of solution for this same problem. You may choose any one for your practices but I will say to go for 1st one because the 1st solution is the best solution for this problem. 1st one consume less memory and less time to execute so go for 1st one.
If you face any problem then go to my YouTube Video and watch it. This video is in Hindi language.
👌👌👌👍👍👍
ReplyDeleteAn easy approach and well defined
ReplyDelete👌👌👌👍👍👍
ReplyDelete👍👍👍
ReplyDelete👍👍👍
ReplyDeletePlz provide us C notes
ReplyDeleteThis comment has been removed by the author.
ReplyDeletePrayas achha hai parantu thoda sa vyakaran trutiyan shudhar loge to aur badhiya ho skta h..... Don't forget,The biggest room in the world is????????????????????????
ReplyDeleteThe room for improvement