Pyramid Problem No. 41

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

A
BA
CBA
DCBA
EDCBA
DCBA
CBA
BA
A

Solving in C:

    #include <stdio.h>
        int main(){
            int row,col,ch; ///charecter=ch
            for(row=1; row<=5; row++){
                for(col=1,ch=64+row; col<=row; col++,ch--) printf("%c",ch); 
                printf("\n");
            }
            for(row=5-1;row>=1; row--){
              for(col=1,ch=64+row; col<=row; 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