How To Print Alphabet C in star pattern ?
What will be the solution of the given star pattern?
This program is executed on DEV C++ editor. You may choose any type of C or C++ editor to execute the program. This program will be same for every editor.
Fig:-1
For the printing the star pattern follow the steps as mentioned below.
Step 1:- I have drawn a box of 3 Column and 5 Rows. I have inserted star in such a way that it can form alphabet C.
Fig:-2
Step 2:- Now see in the fig 2. We can divide the star pattern in two parts 1st part for 0th row and 4th row and 2nd part as 0th column.
Fig:- 3
Step 3:- We have to write the condition for the 1st part and the second part. Now condition for 1st part.
If row = 0 or row =4 and column != 0 (! => Not symbol )
then only we have to print star. Now for the 2nd part.
If column = 0 and row != 0 or row != 4 (! => Not symbol )
then only we have to print star. This is 2 condition on which execution we will have to print star other wise print space.
Programming
#include<stdio.h>
#include<conio.h>
int main()
{
int row,col; // data type decleration
for(row=0;row<=4;row++) // for rows
{
for(col=0;col<=2;col++) //for columns
{
if((row==0 || row==4) && col!=0) //condition for printing star
{
printf(" *");
}
else if( row!=4 && row!=0 && col== 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 while execution then comment below in the comment section so that I can help you Or you can go to my YouTube video.
Thank you ✨💐
ReplyDeleteIt's very helpful
Keep it up bro...
ReplyDeleteLots of best wishes from UP....😍👍
Masha Allah Manish Sir bhot badhiya
ReplyDelete