Search C Program

Star Pattern - 7

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

#include <stdio.h>

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

19 comments:

  1. output is printing different pattern..Please verify the code

    ReplyDelete
    Replies
    1. its working fine, check the codepad execution http://codepad.org/dWs0Cp2I

      Delete
  2. for(k=1;k<i;k++)
    {
    printf(" ");
    }
    This above Segment should be added one more time below the same above segment.

    ReplyDelete
    Replies
    1. i am using codepad.org for validating the code. please check http://codepad.org/Lf8I9vMj

      Delete
  3. # include
    # include
    void main()
    {
    clrscr();
    int i,j,k;
    for(i=1;i<=5;i++)
    {
    for(j=1;j<=6-i;j++)
    {
    cout<<"*";
    }
    for(k=1;k<((2*i)-1);k++)
    {
    cout<<" ";
    }
    for(j=1;j<=6-i;j++)
    {
    cout<<"*";
    }
    cout<<"\n";
    }
    for(i=4;i>=1;i--)
    {
    for(j=5;j>=i;j--)
    {
    cout<<"*";
    }
    for(k=1;k<((2*i)-1);k++)
    {
    cout<<" ";
    }
    for(j=5;j>=i;j--)
    {
    cout<<"*";
    }
    cout<<"\n";
    }


    getch();
    }



    the above code i tried is not working ...
    i have made some modification in the code and it is working..
    you can verify... :-)

    ReplyDelete
    Replies
    1. This one is perfect!! The one by main author is not fitting in precisely to the problem. Although no credit away from him as its(this site) a pretty good job overall!! Cheers!!

      Delete
    2. This is perfect program but in last pattern I face double space problem. So 2nd time use k<=((2*i)-1) as k<=((2*i)-2)

      Delete
  4. also
    for(k=1;k<5-i;k++)
    {
    printf(" ");
    }
    include below the same segment

    ReplyDelete
  5. for(k=1;k<=5-i;k++)
    {
    printf(" ");
    }
    k=1 is wrong it would be k=i.
    instead it would be this will be 2 times
    for(k=i;k<=5-i;k++)
    {
    printf(" ");
    }
    for(k=i;k<=5-i;k++)
    {
    printf(" ");
    }

    ReplyDelete
  6. =$a && $j<=$b && $i!=1 && $i!=10)
    {
    echo "@";
    }
    else
    {
    echo ".";
    }

    }
    echo "\n";
    }

    for($i=5;$i>=1;$i--)
    {
    for($j=10;$j>=1;$j--)
    {
    $a=5-($i-2);
    $b=5+($i-1);
    if($j>=$a && $j<=$b && $i!=1 && $i!=10)
    {
    echo "v";
    }
    else
    {
    echo "~";
    }

    }
    echo "\n";
    }
    ?>

    ReplyDelete
  7. This generalized code is working fine!!

    #include
    void main()
    {
    int i,j,k,n,l,m;
    printf("Enter the number of rows: \n");
    scanf("%d",&n);
    for(i=1;i<=n/2;i++)
    {
    for(j=i;j<=n/2;j++)
    {
    printf("*");
    }
    for(k=1;kn/2;l--)
    {
    printf("*");
    }
    for(m=i+1;mn/2;l--)
    {
    printf("*");
    }
    printf("\n");
    }
    }

    ReplyDelete
  8. he has just printed double spaces with k variable in first half sequence, the code is fine.

    ReplyDelete
  9. i want to code a rectangle of stars within a rectangle of stars can anybody help me thanks?

    ReplyDelete
  10. #include
    void main()
    {
    int i,j,k;
    for(i=1;i<=5;i++)
    {
    for(j=1;j<5;j++)
    {
    for(k=1,k<(i*2);k++)
    {
    printf("*");
    }
    }
    }
    }

    ReplyDelete
  11. This is generalized code:

    #include
    #include

    int main()
    {
    int row,colt,cols,n;
    printf("No of rows:");
    scanf("%d",&n);
    for(row=1;row<=n/2+1;row++)
    {
    for(cols=n/2-row+2;cols>=1;cols--)
    printf("*");
    for(colt=n/2+1;colt>((n/2)+1-(row-1));colt--)
    printf(" ");
    for(colt=n/2+1;colt>((n/2)+1-(row-1));colt--)
    printf(" ");
    for(cols=n/2-row+2;cols>=1;cols--)
    printf("*");
    printf("\n");
    }
    for(row=n/2+1;row>=1;row--)
    {
    for(cols=n/2-row+2;cols>=1;cols--)
    printf("*");
    for(colt=n/2+1;colt>((n/2)+1-(row-1));colt--)
    printf(" ");
    for(colt=n/2+1;colt>((n/2)+1-(row-1));colt--)
    printf(" ");
    for(cols=n/2-row+2;cols>=1;cols--)
    printf("*");
    printf("\n");
    }
    return 0;
    }

    ReplyDelete
  12. #include

    int main()
    {
    int r,i,j,k,l,m,n,p;

    printf("Enter the no. of rows (better be odd) : ");
    scanf("%d",&r);

    m = r/2+1;
    n = r - m;

    for(i=1;i<=r;i++)
    {
    if(i<=m)
    {
    for(j=1;j<=m-i+1;j++)
    {
    printf("*");
    }
    for(k=1;k<=2*(i-1);k++)
    {
    printf(" ");
    }
    for(l=1;l<=m-i+1;l++)
    {
    printf("*");
    }
    }
    else
    {
    p = i-n;

    for(j=1;j<=p;j++)
    {
    printf("*");
    }
    for(k=1;k<=(r+1)-(2*p);k++)
    {
    printf(" ");
    }
    for(l=1;l<=p;l++)
    {
    printf("*");
    }
    }
    printf("\n");
    }

    return 0;
    }

    ReplyDelete
  13. //it's working fine and its simple. try it...
    #include
    using namespace std;
    int main(){
    int n;
    cin>>n;
    int k=-1;
    for(int i=0;i<=n;i++)
    { i<=(n/2)?k++:k--;
    for(int j=0;j<=n;j++){
    if((j<=(n/2)-k)||(j>=(n/2)+k))
    cout<<"* ";
    else
    cout<<" ";
    }
    cout<<"\n";
    }
    return 0;
    }

    ReplyDelete