Pyramid Problem No. 62

 Q.62 Write a C program to print the following character pyramid:

A
BA
ABA
BABA
ABABA

Solving in C:

#include <stdio.h>
    int main(){
        int row,col;
        for(row=1; row<=5; row++){
            for(col=1;col<=row; col++){
                if((row%2==0 && col%2==1) || (row%2==1 && col%2==0)) printf("B");
                else printf("A");
            }
            printf("\n");
        }
        return 0;
    }

Comments

Popular posts from this blog

Pyramid Problem No. 90

Pyramid Problem No. 74

Pyramid Problem No. 85