Thursday, March 29, 2012

character pattern c code

#include<stdio.h>
 
main()
{
   int n, c, k, space = 0;
   char ch, temp;
 
   scanf("%d", &n);
 
   ch = 'A'+n-1;
   temp = ch;
 
   for ( k = n ; k >= 1 ; k-- )
   {
      for ( c = 1 ; c <= space; c++)
         printf(" ");
 
      space++;
 
      for ( c = 1 ; c <= k ; c++ )
      {
         printf("%c",temp);
         temp--;
      }
 
      printf("\n");
      ch--;
      temp = ch; 
   }
 
   return 0;
}
 
 
o/p -
EDCBA
 DCBA
  CBA
   BA
    A