Skip to main content

Posts

Showing posts from July, 2014

C programs to create pyramid structures

Q1.  Write a C program to create pyramid structure as shown below : 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 Code: //Author : Lakshmikant A. Deshpande #include<stdio.h> #include<stdlib.h> void main() { int i=1,j=5; for(i=1;i<=5;i++) { for(j=1;j<=i;j++) printf("%d ",j); printf("\n"); } } Q2.  Write a C program to create pyramid structure as shown below :     1      1 2     1 2 3  1 2 3 4 1 2 3 4 5 Code: //Author : Lakshmikant A. Deshpande #include<stdio.h> #include<stdlib.h> void main() { int spaces=4; int i,j,k; for(i=1;i<=5;i++) { for(k=0;k<spaces;k++) //Print spaces printf(" "); for(j=1;j<=i;j++) { printf("%d ",j); } for(k=0;k<spaces;k++) //Print spaces