Program to print pattern as shown in sample output.
Sample Input5
Sample Output
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
Solution in | C | JAVA | PYTHON |
---|
#include<stdio.h>
int main() {
int n,row,col;
char ch='A';
scanf("%d",&n);
for(row=1;row<=n;row++){
for(col=1;col<=row;col++)
printf("%c",ch+col-1);
for(col=row;col>1;col--)
printf("%c",ch+col-2);
printf("\n");
}
return 0;
}
int main() {
int n,row,col;
char ch='A';
scanf("%d",&n);
for(row=1;row<=n;row++){
for(col=1;col<=row;col++)
printf("%c",ch+col-1);
for(col=row;col>1;col--)
printf("%c",ch+col-2);
printf("\n");
}
return 0;
}
Input
5
Output
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
5
Output
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA