Square triangle2

Q. write a C program to display the character in following fashion:


ABCDCBA
 ABCBA
  ABA
   A
Ans.

#include<stdio.h>
#include<conio.h>
int main()
{
  char ch,r,c;
  int sp;
  printf("
Enter last character of triangle : "
);

  scanf("%c",&ch);
  if(ch>=a && ch<=z)
      ch=ch-32;
  printf("
"
);

  for(r=A; A<=ch; ch--,r++)
  {
    for(sp=r; sp>A; sp--)
       printf(" ");
    for(c=A; c<=ch; c++)
       printf("%c",c);   
    for(c=ch-1; c>=A; c--)
       printf("%c",c);
    printf("
"
);

  }
  getch();
  return 0;
}

/*************** OUTPUT**************/

Related Posts by Categories

0 comments:

Post a Comment