9.18.2015

Character Pattern Program In C

Q. Write a character pattern program in C as following:

    ABCDEDCBA
    ABCDCBA
    ABCBA
    ABA
    A

Ans.

Before we start to source code of above character pattern program, if you look carefully on above character pattern, there are 2 character pattern shows as:

    ABCDEDCBA
    ABCDCBA
    ABCBA
    ABA
    A

so just make above 2 character pattern and merge them, you are done. Cheers!!
Let's start the coding in C.

/*character pattern program in C*/
#include<stdio.h>
int main()
{
  char r,c,ch,h;
  printf("Enter any charactr : ");
  scanf("%c", &ch);
  if(ch>='a' && ch<='z')
     ch=ch-32;

  h=ch;
  for(r='A'; r<=ch; r++,h--)
  {
     for(c='A'; c<=h; c++)
         printf("%c", c);
     for(c=h-1; c>='A'; c--)
         printf("%c",c);
     printf("\n");
  }
 getch();
 return 0;
}

/**************************************************
The output of above program would be:
**************************************************/

Output of Character Pattern Program In C
Figure: Screen shot for Character Pattern Program In C

You might also like:

  1. Number pattern program in C
  2. Big list of 98+ C pyramid programs
  3. Latest user asking pyramid program list

No comments:

Post a Comment