13 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
                printf(" ");  
           printf("\n");  
           spaces--;  
      }  
 }  

2 comments:

  1. CitySpidey is India's first and definitive platform for hyper local community news, RWA Management Solutions and Account Billing Software for Housing Societies. We also offer residential soceity news of Noida, Dwarka, Indirapuram, Gurgaon and Faridabad.

    Free Apartment Management Software
    Apartment Accounting Software
    Apartment Maintenance Software
    RWA Management Tools
    Neighbourhood Management Tools
    Visitor Management System
    Online Neighbourhood Directory
    Online RWA/Society Bill Payment
    Free Neighbourhood Directory

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete