Pyramid Problem No. 17

 Q.17 Write a program to generate a following numbers structure:

				1				
			1	2	1			
		1	2	3	2	1		
	1	2	3	4	3	2	1	
1	2	3	4	5	4	3	2	1


Solving in C:

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

Comments

Popular posts from this blog

Pyramid Problem No. 90

Pyramid Problem No. 74

Pyramid Problem No. 85