Pyramid Problem No. 93

 Q.93 Print positive-negative number triangle as:

9 
8  6
7  5  3
4  2  0 -2
1 -1 -3 -5 -7

Solving in C:

#include <stdio.h>
int main(){
    int n=5,row,col,count_pos=9,count_neg=8;
    for(row=1; row<=n; row++){
        for(col=1; col<=row; col++){
            if(row%2==0) {
                printf("%3d ",count_neg);
                count_neg-=2;
                
            }
            else {
                printf("%3d ",count_pos);
                count_pos-=2;
            }
        } 
        printf("\n");
    }
    return 0;
}

Comments

Popular posts from this blog

Pyramid Problem No. 90

Pyramid Problem No. 74

Pyramid Problem No. 85