About Us

Popular Updates Of Last Week

Search This Website

Saturday 29 July 2017

C Programs to Print Different Pattern Series

C Programs to Print Different Pattern Series

There are few Pyramid Programs in C. Like Print Star Series and Different Pattern Printing Programs in C Language.

Pattern printing programs contains Star Pattern printing.

All Pyramid and Pattern Printing programs based on problems popularity and frequently asked in Interview, these programs has explanation.




Following Are Few Examples of the pyramid pattern:-

Program - 1

v C program to print following Pyramid:   

    *   

    **   

    ***   

    **** 

    *****

ü  #include<stdio.h>
  #include<conio.h>  
  #define MAX 5
   void main()  
   {
       int i,j;     
       for(i=0; i<MAX;i++) 
       {                
           for(j=0;j<=i;j++)
           {
            printf("*");
        }
        printf("\n");
    }
   }                     

Program - 2

v C program to print following Pyramid:    

     *****    

     ****    

     ***    

     **    

     * 

ü       #include<stdio.h>  
   #include<conio.h>  
   #define MAX 5

void main()
{
    int i,j;

    for(i=MAX; i>=0; i--)
    {
        for(j=0;j<=i;j++)
        {
            printf("*");
        }
        printf("\n");
    }
    
}


Program - 3

v     program to print following Pyramid:

                                                *
                * *
               * * *
              * * * *
             * * * * *            

ü    #include<stdio.h>
    #include<conio.h>    
   #define MAX 5

  void main()
  {
    int i,j;
    int space=4;
    /*run loop (parent loop) till number of rows*/
    for(i=0;i< MAX;i++)
    {
        /*loop for initially space, before star printing*/
        for(j=0;j< space;j++)
        {
            printf(" ");
        }
        for(j=0;j<=i;j++)
        {
            printf("* ");
        }
   
        printf("\n");
        space--;    /* decrement one space after one row*/
    }
  }

Program – 4

v C program to print following Pyramid:

                 *
       * *
      * * *
     * * * *
    * * * * *
    * * * * *
     * * * *
      * * *
       * *
        *

ü #include<stdio.h>  
  #include<conio.h>  
  #define MAX 5   
void main()
  {
    int i,j;
    int space=4;

    /*parent loop till number of rows*/

    for(i=0;i< MAX;i++)
    {
    /*loop for initially space, before star printing*/
        for(j=0;j< space;j++)
        {
            printf(" ");
        }
        for(j=0;j<=i;j++)
        {
            printf("* ");
        }
         
        printf("\n");
        space--;
    }

    /*repeat it again*/
    space=0;
    /*parent loop till number of rows*/
    for(i=MAX;i>0;i--)
    {
    /*loop for initially space, before star printing*/
        for(j=0;j< space;j++)
        {
            printf(" ");
        }
        for(j=0;j< i;j++)
        {
            printf("* ");
        }
         
        printf("\n");
        space++;
    }
   }

 Program – 5

v C program to print following Pyramid:

        **********
        ****  ****
        ***    ***
        **      **
        *        *

                    ü    #include<stdio.h>
         #include<conio.h>
   #define MAX 5

int main()
{
    int i,j;
    int space=0;
    /*run loop (parent loop) till number of rows*/
    for(i=MAX;i>0;i--)
    {
        /*print first set of stars*/
        for(j=0;j< i;j++)
        {
            printf("*");
        }
        for(j=0;j< space;j++)
        {
            printf(" ");
        }
        /*print second set of stars*/
        for(j=0;j< i;j++)
        {
            printf("*");
        }
         
        printf("\n");
        space+=2;
    }
}
  

No comments:

Post a Comment