Pages

  • Home
  • About & Contact
  • Archive
  • C Programming Examples

09 January 2012

Simple star pattern programs in c

Here there are Few examples of Star pattern programs in cWant to learn to solve patterns on your own than try this  How to solve [Code] Pattern Programs in C

Simple star pattern programs in c

pattern1 : Print the stars
      *
      **
      ***


#include<conio.h>
#include<stdio.h>
void main()
{
    int i,j,n;
    clrscr();
    printf("\nEneter the no of lines to be printed: ");

    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
       for(j=0;j<=i;j++)
       {
           printf("*");
       }
       printf("\n");
    }
    getch();
}




Satr pattern 2
   *
  **
    ***





#include<conio.h>
#include<stdio.h>
void main()
{
    int i,j,n;
    clrscr();

    printf("\nEneter the no of lines to be printed: ");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
       for(j=n-i;j>1;j--)
       {
           printf(" ");
       }
       for(j=0;j<=i;j++)
       {
          printf("*");
       }
       printf("\n");
    }
    getch();
}



                                                                                                            


        Star pattern 3 


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




#include<conio.h>
#include<stdio.h>
void main()
{
    int i,j,n,k;
    clrscr();

    printf("\nEnter the no of lines to be printed: ");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
       for(j=0;j<n-i;j++)
       {
          printf("*");
       }
       for(k=0;k<(2*n-2*j);k++)
       {
            printf(" ");     //for spaces
       }
     for(j=0;j<n-i;j++)
       {
          printf("*");
       }
       printf("\n");
    }
    getch();
}








Star pattern 4







#include<conio.h>
#include<stdio.h>
void main()
{
    int i,j,n,k;
    clrscr();

    printf("\nEnter the no of lines to be printed: ");
    scanf("%d",&n);
    printf("\n\n");
    for(i=0;i<n;i++)
    {
       for(j=0;j<n-i;j++)
       {
         printf("*");
       }
       for(k=0;k<(2*n-2*j);k++)
       {
          printf(" ");
       }
for(j=0;j<n-i;j++)
       {
          printf("*");
       }
       printf("\n");
    }
    for(i=0;i<n;i++)
    {
       for(j=0;j<=i;j++)
       {
           printf("*");
       }
       for(k=2*n-2*j;k>0;k--)
       {
            printf(" ");
       }
for(j=0;j<=i;j++)
       {
          printf("*");
       }
       printf("\n");
    }

    getch();
}





Star pattern 5
      *
     ***
   ******
     ***
       *






#include<conio.h>
#include<stdio.h>
void main()
{
   int i,j,k,n;
   clrscr();

   printf("\nEnter the no lines to be printed: ");
   scanf("%d",&n);
   printf("\n\n");
   for(i=0;i<n;i++)
   {
      for(j=0;j<(n-i-1);j++)
  printf(" ");
      for(k=0;k<(2*i+1);k++)
  printf("*");
      printf("\n");
   }
      for(i=0;i<n-1;i++)
   {
      for(j=0;j<=i;j++)
  printf(" ");
      for(k=(2*n-2*i-3);k>0;k--)
  printf("*");
      printf("\n");
   }
}






Star pattern :6 [Diamond pattern]

  *
*  *
   *     *
*  *
  *

#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,k,n;
clrscr();
printf("Enter the number of lines to be printed");
scanf("%d",&n);
for(i=0;i<n;i++)
{
      for(j=n-i-1;j>0;j--)
            printf(" ");
      printf("*");
      for(k=2*i-1;k>0;k--)
            printf(" ");             //code for upper triangle
      if(i!=0)
            printf("*");
      printf("\n");
 }
 for(i=n-1;i>0;i--)
 {
      for(j=0;j<n-i;j++)
            printf(" ");                
      printf("*");                  //code for lower triangle
       for(k=2*i-3;k>0;k--)
           printf(" ");
      if(i!=1)
            printf("*");
      printf("\n");
   }
 getch();
}

simple star pyramid
program for simple star pyramid

pattern 7:





//#include<conio.h>
#include<stdio.h>
void main()
{
         int i,j,k,n;
         //clrscr();
         printf("Enter the number of lines to be ptinted");
         scanf("%d",&n);
         for(i=0;i<n;i++)
         {
                 for(j=i;j<n;j++)
                {
                        printf(" ");                                // spaces
                }
                for(k=0;k<2*i-1;k++)
                {
                       printf("*");                                // star
                 }
                 printf("\n");
          }
}

star pyramid reverse
program for simple star pyramid in reverse order

pattern 8:






//#include<conio.h>
#include<stdio.h>
void main()
{
            int i,j,k,n;
            //clrscr();
            printf("Enter the number of lines to be ptinted");
            scanf("%d",&n);
            for(i=0;i<n;i++)
           {
                     for(j=0;j<i;j++)
                   {
                          printf(" ");
                    }
                    for(k=2*(n-i);k>1 ;k--)
                    {
                          printf("*");
                    }
                   printf("\n");
            }
}

The program below is good program can be asked for coding compititions 




arrow pattern
 program for arrow pattern


pattern 8:







//#include<conio.h>
#include<stdio.h>
void main()
{
            int i,j,k,n;
            clrscr();
           printf("Enter the number of lines to be ptinted");
           scanf("%d",&n);
           for(i=0;i<n;i++)
          {
                     for(j=0;j<i;j++)
                    {
                             printf(" ");
                     }
                     for(k=0;k<i;k++)
                     {
                                 printf("*");
                       }
                      printf("\n");
         }


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

pattern 9:
Not that Simple program to print hollow pattern triangle.


#include<conio.h>
#include<stdio.h>
void main()
{
      int i,j,k,n;
      clrscr();
      printf("Enter the number of lines to be printed:");
      scanf("%d",&n);
      printf("\n");
      for(i=1;i<2*(n-2);i++)
              printf(" ");
       printf("*\n");
       for(i=1;i<n-1;i++)
      {
              for(j=n-i;j>0;j--)
                      printf(" ");
              printf("*");
              for(k=0;k<2*i-1;k++)
                       printf(" ");
              printf("*\n");
     }
     printf(" ");
     for(i=0;i<2*n-1;i++)
     printf("*");
}



pattern 10:
Simple Square pattern program in c


#include<conio.h>
#include<stdio.h>
void main()
{
       int i,j,k,n;
       clrscr();
       printf("Enter the number of lines to be printed:");
       scanf("%d",&n);
       for(i=0;i<n;i++)
             printf("*");
       printf("\n");
       for(i=0;i<n-2;i++)
       {
              printf("*");
              for(j=0;j<n-2;j++)
                     printf(" ");
              printf("*\n");
       }
        for(i=0;i<n;i++)
              printf("*");
}

Similar programs:


pattern programs in c++ [alphabet pattern]

C++ Simple star pattern programs


pattern programs in c in number pattern
pattern programs in c. [alphabet pattern]

How to solve [Code] Pattern Programs in C

Share your views regarding the given post via the comments section given below.
If you liked the post, please '+1' it & share it on other social networks.
Thank You.

58 comments:

  1. Anonymous28 June, 2012

    line 15 of star pattern 8- star pyramid in riverse is
    for(k=2*(n-i);k>1 ;k--) =>this is wrong
    it should be => for(k=2*(n-i)+1;k>1 ;k--)

    ReplyDelete
  2. Hey,
    Thanks for your comment
    But mine program correct.I have tested both the programs.Mine program output is same as shown in the image.
    Your programs output would be as follows:
    **********
    ********
    ******
    ****
    **
    But still if you have any problem you can contact me at programmingspark@gmail.com

    ReplyDelete
    Replies
    1. In comment's,spaces are not shown

      Delete
  3. thanks for giving useful code plz give java code also

    ReplyDelete
    Replies
    1. You are welcome,
      I would be starting with java,later on.

      Delete
    2. i'll give you java code

      Delete
  4. hiii romil !! plz tell me the logic how did u do that,,.. i mean is there any technique/logic to solve these kind of problem ....

    ReplyDelete
    Replies
    1. yaah, give me some time
      I may post something that will help you.

      Delete
    2. dude only just practice this types of pattern ....
      and apply a logic your self .. after that u can solve very easily ...and develop your logic

      Delete
  5. man!!you r d bomb !! awesome....
    take ur time !! if u have facebook id lemme knw !!!
    or join me www.facebook.com/vicky.dx1

    ReplyDelete
  6. here i have tried to explain

    www.programmingspark.com/2012/09/how-to-solve-code-pattern-programs-in-c.html

    hope you like it

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

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

    ReplyDelete
  9. *
    * *
    * * *
    * * * *


    bro can you solve my above pattern ?

    ReplyDelete
    Replies
    1. #include
      #include
      void main()
      {
      for(i=1;i<=4;i++)
      {
      for(i=1;i<=i;i++)
      printf("*");
      printf("\n")
      }
      getch();
      }

      Delete
  10. Swagatam the above pattern is the first program of this post

    #include
    #include
    void main()
    {
    int i,j,n;
    clrscr();
    printf("\nEneter the no of lines to be printed: ");

    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
    for(j=0;j<=i;j++)
    {
    printf("*");
    }
    printf("\n");
    }
    getch();
    }

    ReplyDelete
  11. write a program for
    * *
    * * * *
    * * * * * *
    * * * * * * * *
    * * * * * * * * *

    ReplyDelete
  12. #include
    #include
    void main()
    {
    int i,j,n,k;
    clrscr();
    printf("\nEneter the no of lines to be printed: ");

    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
    //for(k=0;k<n-i;k++) //for printing spaces
    // printf(" ");
    for(j=0;j<=2*i+1;j++)
    {
    printf("*");
    }
    printf("\n");
    }
    getch();
    }

    ReplyDelete
  13. Guys sorry for the inconvenience, as I will not be able to answer your question till 15 dec as my exams are going on.
    -ADMIN

    ReplyDelete
  14. ---------------------
    for(k=0;k<2*i-1;k++)
    ---------------------
    I cant understand this logic(2*i-1), please reply me ASA possible.
    Thank you!

    ReplyDelete
  15. * *
    * * * *
    * * * * * *
    * * * * * * * *
    * * * * * * * * *

    ReplyDelete
  16. * *
    * * * *
    * * * * * *
    * * * * * * * *
    * * * * * * * * *

    ReplyDelete
    Replies
    1. #include
      #include
      void main()
      {
      int i,j,n;
      clrscr();
      printf("Enter the number of lines to be printed: ");
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
      for(j=1;j<=2*i;j++)
      {
      printf("*");
      }
      printf("\n");
      }
      getch();
      }

      Delete
  17. Prdaeep

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

    ReplyDelete
  18. Replies
    1. please use . instead of space as spaces are not printed in comments

      Delete
  19. plz somebody help me with this...
    * * * * *
    * *
    * * * * *
    * *
    * * * * *

    ReplyDelete
    Replies
    1. #include"stdio.h"
      void main()
      {
      int i,j,n;
      clrscr();
      printf("Enter the number of lines to be printed: ");
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
      if(i%2)
      printf("*****");
      else
      printf("**");
      printf("\n");
      }
      getch();
      }

      is there any spaces not printed in your comment
      please use . instead of space

      Delete
  20. This comment has been removed by the author.

    ReplyDelete
  21. pls give me the ans for this pattern untill tommorrow pls

    *
    _**
    ***
    ___****
    *****
    _____******
    *******...uptill n pls give the ans as soon as possible

    ReplyDelete
  22. #include
    void main()
    {
    int i,j,k,n;
    printf("\nEneter the no of lines to be
    printed: ");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
    if(i%2)
    {
    for(k=0;k<i;k++)
    printf(" ");
    }
    for(j=0;j<=i;j++)
    {
    printf("*");
    }
    printf("\n");
    }
    }

    ReplyDelete
  23. guys i am not able to comment properly as "less than " sign is not getting printed in this template so please provide your email while asking doubts and solution will be provided to you on your mail.
    no spam mails will be send.

    ReplyDelete
    Replies
    1. Hi can you help me with this one


      _**********
      **________**
      **________**
      **________**
      **________**
      **________**
      **________**
      **________**
      _**********


      Thanks I need This For My Midterm Exam. The Output Should be In The
      The Center..


      Delete
  24. Anonymous23 May, 2013

    Pattern 10 is a wrong one does anyone know the solutio

    ReplyDelete
  25. Anonymous26 May, 2013

    You can get more C PROGRAMS, PATTERNS AND OTHER KNOWLEDGE AT www.facebook.com/itsagarsol
    -----
    Like page to get updated posts and also share your knowledge for the benefit of others.....
    SHARE WITH CARE ...

    ReplyDelete
  26. Anonymous28 May, 2013

    write a program for
    * *
    * *
    *
    * *
    * *

    ReplyDelete
    Replies
    1. int main()
      {
      int i,n;
      printf("enter the no:");
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
      if(i%3==0)
      printf("*");
      else
      printf("* *");
      printf("\n");
      }
      }

      Delete
    2. Hi can you help me with this one


      _**********
      **________**
      **________**
      **________**
      **________**
      **________**
      **________**
      **________**
      _**********


      Thanks I need This For My Midterm Exam. The Output Should be In The
      The Center..

      Delete
  27. Anonymous14 June, 2013

    how to print this pattern any one help me please?

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

    ReplyDelete
  28. i need a programe to print folloing pattern
    * * * * * *
    * * * * *
    * * * *
    * * *
    *

    ReplyDelete
  29. void main()
    int i,j;
    clrscr();
    {
    for(i=0;i<=5;i+=)
    {
    for(j=i;j<=3;j++)
    {
    printf(""*\t");
    }
    printf("\n")
    }
    getch();
    }

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

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

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

    ReplyDelete
  33. Hi can you help me with this one


    _**********
    **________**
    **________**
    **________**
    **________**
    **________**
    **________**
    **________**
    _**********


    Thanks I need This For My Midterm Exam. The Output Should be In The
    The Center..


    i dunno how can i use gotoxy

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

    ReplyDelete
  35. *
    * *
    * * *
    &* * * *

    Where & = space

    ReplyDelete
  36. * * * * * * * * *
    * * * *
    * * * *
    * * * *
    * *
    * * * *
    * * * *
    * * * *
    * * * * * * * * *

    try this

    ReplyDelete
  37. can u help for this
    *
    * *
    * * *
    * *
    *

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

    ReplyDelete
  39. can u help me with this if the user enter 8 then it prints
    -- *
    -- **
    - ****
    -******
    *********
    program only takes even inputs... _ underscores are representing spaces

    ReplyDelete
  40. can any body explain me these programs, how do they work?

    ReplyDelete
  41. plz give me reply...how to draw pattern program using a single for loop...

    ReplyDelete
  42. can someone help me for this kind of star (israel's star)
    *
    * *
    * * * * *
    * * * *
    * * * * *
    * *
    *

    ReplyDelete

Back To Top