How To Print Alphabet E in Star Pattern
What will be the solution for the given star pattern?
Fig:-1
This program is executed on DEV C++ editor. You may choose any C or C++ editor to execute the program logic and programming will be same for all.
For printing the above star pattern follows the step mentioned below.
Step 1:- Draw a box of 4 column and 5 row. And insert star in such way that is form alphabet E as given in fig:-2
Fig :-2
Step 2:- Now we have divided fig :-2 in two part so that we can easily write the code.
Fig :-3
Step 3:- Now time for logic part if you will see in fig :-3 part 1 then you will find that figure is like rectangle with one side open.
1st part logic:-
if row =0 or row =4 or column = 0 then only print star.
2nd part logic:-
if row = 2 and column % 3 != 0 then only print star.
These are the 2 condition when we have to print star otherwise we have to print blank space. No time for programming.
Programming
#include<stdio.h>
#include<conio.h>
int main()
{
int row, col; //Data type deceleration
for(row=0;row<=4;row++) //For rows
{
for(col=0;col<=3;col++) //For columns
{
if(row==0 || row == 4 || col==0) //Condition for printing star
{
printf(" *");
}
else if(row==2 && col%3!=0) //Condition for printing star
{
printf(" *");
}
else //For blank space
{
printf(" ");
}
}
printf("\n"); //for new line
}
getch();
return 0;
}
Output
Fig :-4
If you face any problem then comment in comment section or visit my YouTube Video.
Very useful
ReplyDeleteKeep it up
💐✨
🐰🐰🐰
ReplyDeleteGood
ReplyDeleteKeep It up Bro
ReplyDeleteawsm
ReplyDelete