How To Print Given Star Pattern.

What will be the solution of given star pattern?

Star pattern

Fig:- 1

This program is executed on DEV C++ editor. You may use any C or C++ editor to execute the program logic will be same.

Step that you have to follow for this programming logic.

Step 1:- We have to draw a box which will contain 5 rows and 5 column.
Fig:-2

Step 2:- We have drawn a box with rows and 5 columns. Now we have to think about its logic portion.
Logic for printing star:-
If column is smaller then or equal to 5 - row
then only we have to print star. Other wise print blank space.

Programming:-

#include<stdio.h>
#include<conio.h>
int main()
{
int row,col;      //Variable deceleration 
for(row=0;row<=4;row++)   //Loop for rows
{
for(col=0;col<=4;col++)  //Loop for column
{
if(col>=(4-row))     //Condition for printing star
{
printf(" *");    
}
else                //Condition for printing blank space 
{
printf("  ");
}
}
printf("\n");       //For new line
}
getch();
return 0;
}

Output:-

Output of the given programming

Fig:-3

This is the logic of the given programming. If you face any problem then comment in comment section or visit my YouTube video. Video is in Hindi language.

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