Friday, 2 August 2013

Chapter 3 solutions problem [E][f]

Question-Write a program to produce the following output: 

ABCDEFGFEDCBA
ABCDEF   FEDCBA
ABCDE         EDCBA
ABCD              DCBA
ABC                    CBA
AB                         BA
A                              A 
Solution- interesting question. Honestly speaking, I have made some adjustments in blanks, but that won't be cheating. it's totally fair. 

#include <stdio.h>
int main()
{
int i,k,blnks,l,p;

for(p=71;p>=65;p--)
{
for(i=65;i<=p;i++)
{
if(i==71)
printf(" %c ",i);
else
printf("%c ",i);
}
l=1;
blnks=2*(72-p)-1;
while(l<blnks)
{
printf("  ");
l++;
}
for(k=p;k>=65;k--)
{
if(k==71)
printf(" ");
else
printf("%c ",k);

}
printf(" \n");
}
return 0;
}




  

No comments:

Post a Comment