Pyramid Problem No. 43

 Q.43 Write a C program to print the following number design/triangle:

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

Solving in C:

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

Comments

Popular posts from this blog

Pyramid Problem No. 90

Pyramid Problem No. 74

Pyramid Problem No. 85