How to print alphabet A in star pattern.
What will be the solution of the given problem?
                                                                                                     Fig:1
This program is executed on DEV C++ editor. You may choose any C or C++ editor to execute the program it will not be same for all editor.
For printing this star pattern you have to follow some steps.
Step 1:-  I have created a table of  5 rows and 4 column. And inserted the following star pattern to form alphabet A. In the given figure.
Fig:-2
Step 2:- Now we have to find the condition for the printing star. In 1st line we have two star means in Row 0 and we have two star in column 1 & 2. For this we have condition.
If Row = 0 and Column = 1 or 2. then we have to print star.
Step 3:- Now we have to print the column for the the formation of A. In all place of Column 0 we have to print star except at Row 0. And same for Column 3. So now condition will be.
If Column = 0 or 3 and Row !=0 then we have to print star.(! => Not)
Step 4:- Now we have to print the line between the Column 0 & 3 in Row 2. For this we have condition
If Row=2 & Column = 1 or 2 then we have to print star.
If you have any doubt in any step then you can comment below. So that I can help you.
Programming
#include<stdio.h>
#include<conio.h>
int main()
{
 int col,row;                                                                              //Data type deceleration
 for(row=0;row<=4;row++)                                                    //For rows
 {
  for(col=0;col<=3;col++)                                                 //For column
  {
  else if(row==0 &&(col==1 || col==2))                          //Condition for printing star
   {
    printf("*");
   }
   else if((col==0 || col==3)&& row!=0)                           //Condition for printing star
   {
    printf("*");
   }
   else if((row==2) && ( col==0 || col==2))                     //Condition for printing star
   {
    printf("*");
   }
   else                                                                           // For blank space 
   {
    printf(" ");
   }
  }
  printf("\n");                                                                    //New line
 }
 getch();
 return 0;
}
Output:-
Fig:-3
Keep Continuing 👌👌👌👍
ReplyDeleteBlogger buddy😁😁
ReplyDelete