How To Print Alphabet B in Star Pattern.

What will be the solution of given star pattern?



Fig : 1

This program is executed on DEV C++ editor . You may choose any C or C++ editor. It will be same for any editor.

For printing star pattern we have to follow some steps.

Step 1:- I have created a box of 4 columns and 7 rows. and insert star in box as like they can form alphabets B. In the given fig: 2

Fig:2


Step 2:- Now you have to find the for printing star. So first we look at column 0. This column is full of star.And if we look at row 0, 3,and 6. then they have same pattern till column 2. So we can write 2 different condition for this start pattern. 

If column = 0 and row must be between 1 and 5. Then only we have to print star.

Step 3:-  Now we have to print star in row 0, 3, and 6 and up to column 2. 

If column is smaller then equal to 2 and row module 3 is equal to 0. Then only we have to print star.

 

 Step 4:- Now we have completed our star pattern up to column 2. Now we have to think about column 3. So if you go through fig:-2 then you will see that there are stars in pair.

If column = 3 and row module 3 is not equal to 0. Then only we have to print star

Programming

#include<stdio.h>
#include<conio.h>
int main()
{
int row,col;   //data type declaration
for(row=0;row<=6;row++) //for rows
{
for(col=0;col<=3;col++)  //for columns
{
if(col==0 && (row>=1 && row<=5) )  // condition for printing star
{
printf(" *");
}
else if(row%3==0 && col<=2)     // condition for printing star
{
printf(" *");
}
else if(col==3 && row%3!=0)    // condition for printing star
{
printf(" *");
}
else                     //for blank space
{
printf("  ");
}
}
printf("\n");    // for new line
}
getch();
return 0;
}

Output


Fig :- 3

If you face any problem while executing this program then comment in comment section. So that I can help you. If you did not understand then go to my YouTube video.




Comments

Post a Comment

Popular posts from this blog

Abundant Number in C Programming || Learning Duniya

Automorphic Number in C Programming || Learning Duniya

How to Print Given Star Pattern