Pyramid Problem No. 38

 Q.38 Write a C program to display the following square character triangle:

      A
     ABA
    ABCBA
   ABCDCBA

Solving in C:

    #include <stdio.h>
    int main(){
        int row,col,ch; ///charecter=ch
        for(row=1; row<=4; row++){
            for(col=1; col<=4-row; col++) printf(" ");
            for(col=1,ch=65; col<=row; col++,ch++) printf("%c",ch); 
            for(col=row-1,ch=64+row-1; col>=1; col--,ch--)printf("%c",ch);
            printf("\n");
        }
        return 0;
    }

Comments

Popular posts from this blog

Pyramid Problem No. 90

Pyramid Problem No. 74

Pyramid Problem No. 85