How to print the alphabet pattern
What will be the solution of alphabets pattern for right angle triangle?
This program is executed on DEV C++ you may choose any C or C++ editor to execute the program code will be same.
Fig:-1
Programming type 1:-
#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<=row;col++) //for column
{
printf(" %c",'A'+row); //printing the alphabet in pattern
}
printf("\n"); // for new line
}
getch();
return 0;
}
Output:-
Fig:-2
Programming type 2:-
#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<=4;col++) //for column
{
if(col<=row) // condition for printing alphabets in pattern
{
printf(" %c",'A'+row); //printing the alphabet in pattern
}
else // for blank space
{
printf(" ");
}
}
printf("\n"); // for new line
}
getch();
return 0;
}
Output
Fig:-3
This pattern can be printed in two ways and both of way coding is above. And in this two type I will prefer 1st type to code because of time complexity. So in these 2 type 1st type is better program. If you did not understand the programming then go to my YouTube Video and watch it.
Bdhiya
ReplyDeleteSuperb bro
ReplyDeleteAwesome bro...,
ReplyDeleteIt was very helpful!😇
ReplyDeleteStunning
ReplyDeletegreat job
ReplyDeletegreat
ReplyDelete