How To Print Alphabet D in Star Pattern
What will be the solution of given star pattern ?
This programming is executed on DEV C++ editor. You may choose any C or C++ editor to execute the program. Logic and the programming will be same.
Fig:-1
For printing above star pattern follow the step mention below.
Step 1:- Draw a box of 4 column and 5 row.  In fig 2 I have inserted star in such a way that it form the D.
Step 2:-  It is same like star pattern of alphabets C  but in this we have divided it into three part and figure are as follows.
Fig :-3
Step 3:- Now we have divided it into three part and we have to write its logic for the programming.
1st part logic:-
If column = 0  then only we have to print star.
2nd part logic:-
If row = 0 or row =4 and column % 3!= 0 then we have to print star.
3rd part logic:-
If column =3 but row != 0 and row !=4 then we have to print star.
These are the 3 condition where we have to print star and rest place we have print the blank space. Now the programming are as follows.
Programming
#include<stdio.h>
#include<conio.h>
int main()
{
	int row, col;    //Data type deceleration
	for(row=0;row<=4;row++)  // For row
	{
		for(col=0;col<=3;col++)   //For column
		{
			if(col==0)     // condition for printing star
			{
				printf(" *");
			}
			else if((row==0 || row==4) && (col%3!=0))     // condition for printing star
			{
				printf(" *");
			}
			else if(col==3 && (row!=0 && row!=4))     // condition for printing star
			{
				printf(" *");
			}
			else
			{
				printf("  ");             // for blank space
			}
		}
		printf("\n");   //for new line
	}
	getch();
	return 0;
}
Output
Fig:- 4
If you face any problem while executing the program then comment in the comment section or visit my YouTube video to understand the logic of this programming.
👍👍
ReplyDeleteGud concept.
ReplyDelete👌👌✌
ReplyDelete