## 12.02.2012

### Character Rectangle Design

Q. Write a C program to print the following character rectangle structure:

ABCBA
AB BA
A   A
AB BA
ABCBA

Ans.

Cross-Reference: Before you reading answer of above program, i recommend to read Number Rectangle Design for easily understand this program.

/*c program for character rectangle pyramid*/
#include<stdio.h>
int main()
{

char ch='C',r,c,q,t,sp,st;
st=ch;
for(r='A'; r<=ch; r++,st--)
{
for(c='A';c<='B'; c++)
{
if(r=='C')
{
printf("A ");
break;
}
else
printf("%c",c);
}
for(sp=r; sp>'A'; sp--)
printf(" ");
for(t=st; t>='A'; t--)
printf("%c",t);
printf("\n");
}
for(r='A'; r<=ch-1; r++)
{
for(c='A'; c<='B'; c++)
printf("%c", c);
for(sp=r; sp<='A'; sp++)
printf(" ");
for(t=r+1; t>='A'; t--)
printf("%c", t);
printf("\n");
}
return 0;
}

The output of above program would be:

 Figure: Screen shot for character rectangle structure C program

1. Hi plz i need the program to display the no 1987653421 separate with hundred,thousands,lakhs and crores

1. @Uma,
Plz describe your question in detailed with example!!

2. Add ','(comma) after 3 char from last position in a string eg input 1205000 output 1,205,000

1. @Uma,
I try to fix this soon.
Check below program it is set comma position from starting point with reverse number.

#include"stdio.h"
#include"conio.h"
int main()
{
long num=12345678;
int i,n,len=0;
n = num;
while(num>=1)
{
len++;
num = num/10;
}
for(i=0; i<=len && n>=1; i++,n=n/10)
{
if(i==3 || i==6 || i==9 || i==12 || i==15 || i==18)
printf(",");
printf("%ld",n%10);
}
getch();
return 0;
}

2. Thank U very much Dinesh

3. A
B A B
C B A B C
B A B
A
please solve this pattern how to display it

1. #Koushik

Your character pattern C program source code at:

http://cprogrammingcodes.blogspot.com/2014/02/character-pyramid.html