Computer Scientists are Pretty Pessimistic

Saturday 3 October 2015

WAP to print the following pattern.

       


CODE ::

#include <stdio.h>
int main ()
{
    int i,j,k,l,s;
    char c,ch,cc;
    printf("Enter a letter (capital letter): ");
    ch=getchar();
    l=ch-'A';
    s=2;
    for(i=l;i>=0;i--)
    {
       if(i==l)
       {
           c='A';
           for(j=0;j<=i;j++)
           {
               printf("%c ",c++);
           }
           c=c-2;
           for(j=0;j<=(i-1);j++)
           {
               printf("%c ",c--);
           }
           printf("\n");
       }
       else
       {
           c='A';
           for(j=0;j<=i;j++)
           {
               printf("%c ",c++);
           }
           c--;
           for(j=0;j<s;j++)
           {
               printf(" ");
           }
           for(j=0;j<=i;j++)
           {
               printf("%c ",c--);
           }
           s=s+4;
           printf("\n");

       }
    }
    return 0;


}

No comments:

Post a Comment