Search C Program

Star Pattern - 5

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

#include <stdio.h>

int main()
{
    int i, j, k;
    for(i=1;i<=5;i++)
    {
        for(j=i;j<5;j++)
        {
            printf(" ");
        }
        for(k=1;k<(i*2);k++)
        {
                printf("*");
        }
        printf("\n");
    }

    return 0;
}
Related Links:
- More Number Pattern Programs
- Star Pattern Programs in C
- Alphabet Pattern Programs in C
- Series Programs in C

35 comments:

  1. good programming, easy to understand!!1

    ReplyDelete
  2. all wrong codes!!!!!!!!!!!!!!!

    ReplyDelete
    Replies
    1. This code is tested on codepad. check this link http://codepad.org/YQSAu3Lq

      Delete
    2. YES, ITS CORRECT.

      Delete
  3. Replies
    1. as i said before this code is verified at codepad.ora, check following link
      http://codepad.org/YQSAu3Lq

      Delete
    2. check the output on http://codepad.org/YQSAu3Lq

      Delete
    3. no its working its coming but not in a triangle shape but in a half triangle

      Delete
  4. #include

    int main()
    {
    int i, j, k;
    for(i=1;i<=5;i++)
    {
    for(j=n-i;j>=1;j--)
    {
    printf(" ");
    }
    for(k=1;k<(2*n-1);k++)
    {
    printf("*");
    }
    printf("\n");
    }

    return 0;
    }

    ReplyDelete
    Replies
    1. @nimish-I can understand that :)
      @Avinash- What is 'n' in --> "for(k=1;k<(2*n-1);k++)" ??

      Delete
    2. #include

      int main()
      {
      int i, j;
      for(i=1;i<=5;i++)
      {
      for(j=1;j<=9;j++)
      {
      if(J>=6-i && j<=4+i)
      {
      print("*");
      }
      else
      {
      printf(" ");
      }

      }
      printf("\n");

      }

      Delete
  5. the code is wrong buddy

    ReplyDelete
    Replies
    1. check running version of this code at http://codepad.org/YQSAu3Lq

      Delete
  6. Check out this code for input of any no of rows:

    #include
    void main()
    {
    int i,j,k,n;
    printf("Enter the no of rows \n");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
    for(j=n;j>i;j--)
    {
    printf(" ");
    }
    for(k=1;k<=i*2-1;k++)
    {
    printf("*");
    }
    printf("\n");
    }
    }

    ReplyDelete
    Replies
    1. you have written the same code,moreover you have rather added few characters to make it cumbersome..

      Delete
  7. this code is right I executed it and successfully got output. please explain it line by line doing specially for(k=1;k<=i*2-1;k++) this loop

    ReplyDelete
  8. this blog is perfect and the 1st code is very easy to understand.

    ReplyDelete
  9. Try this one.

    #include
    int main()
    {
    int i,j,n;
    printf("Enter a value=\n");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
    for(j=1;j<=n-i;j++)
    printf(" ");
    for(j=1;j<=2*i-1;j++)
    printf("*");
    printf("\n");
    }
    //printf("\n");
    return 0;
    }

    ReplyDelete
  10. Dear anonymous, we got that it's wrong code than why don't you provide the right code instead of captioning wrong code at every comment. Plz provide soln not suggestions or statements. 😊

    ReplyDelete
  11. The code is working fine :) thanks

    ReplyDelete
  12. how you are managing spaces in the pattern?

    ReplyDelete
  13. in the third loop there should be 2*i-1.That,s it and every thing is fucking fine

    ReplyDelete
    Replies
    1. What you said was right dude. ��

      Delete
  14. Main()
    {int I, j;
    for(I=0;I<=4;I++)
    for(j=4-I; j<=4+I; j++)
    Printf("*");

    }

    ReplyDelete
  15. can you describe the logic of the program

    ReplyDelete