How to print the alphabet pattern

What will be the solution of alphabets pattern for right angle triangle?
Alphabet pattern
Fig:-1


This program is executed on DEV C++ you may choose any C or C++ editor to execute the program code will be same.

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:-

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
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. 

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