Search C Program

Star Pattern - 9

    *
   * *
  *   *
 *     *
*       *
 *     *
  *   *
   * *
    * 
int main()
{
    int i, j;
    
    for(i=1; i<=5; i++)
    {
        for(j=5; j>i; j--)
        {
            printf(" ");
        }
      printf("*");
        for(j=1; j<(i-1)*2; j++)
        {
            printf(" ");
        }
        if(i==1) printf("\n");
      else printf("*\n");
    }
    
    for(i=4; i>=1; i--)
    {
        for(j=5; j>i; j--)
        {
            printf(" ");
        }
      printf("*");
        for(j=1; j<(i-1)*2; j++)
        {
            printf(" ");
        }
        if(i==1) printf("\n");
      else printf("*\n");
    }    
    
    return 0;
}
Related Links:
- More Number Pattern Programs
- Star Pattern Programs in C
- Alphabet Pattern Programs in C
- Series Programs in C

13 comments:

  1. this program is wrong..!!!! please someone change the code!!!

    ReplyDelete
    Replies
    1. @Rajesh Hariharan-- Would you please be kind and not rude. If the programming code is wrong explain why and provide the right code. It is not right to say someone is wrong. Rather tell it could be a mistake.

      Delete
  2. #include
    using namespace std;

    int main(){
    int i,j,k,n;
    cout<<"Enter a odd No for Diamond Star Pattern ";
    cin>>n;
    for(i=1;i<=n;i++){
    if(i<=(n+1)/2){
    for(j=i;j<(n+1)/2;j++){
    cout<<" ";
    }
    }else{
    for(j=1;j<=(i-(n+1)/2);j++){
    cout<<" ";
    }
    }

    if(i<=(n+1)/2){
    for(k=1;k<2*i;k++){
    if(k==1 || k==2*i-1)
    cout<<"*";
    else
    cout<<" ";
    }
    }else{
    for(k=0;k<(2*n-2*i)+1;k++){
    if(k==0 || k==(2*n-2*i) )
    cout<<"*";
    else
    cout<<" ";
    }
    }
    cout<<endl;
    }
    }

    ReplyDelete
  3. #include
    void main(){
    int i,j,k,n=10,m,s;
    for(i=1;i<=n;i++){
    for(s=i;s=1;i--){
    for(s=n;s>i;s--){
    printf(" ");
    }
    printf(" *");
    for(j=i;j>1;j--){
    printf(" ");
    }
    if(i!=1)
    printf("*");
    printf("\n");
    }
    }

    ReplyDelete
  4. #include
    #include

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

    printf("*\n");
    }
    }


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

    ReplyDelete
  5. #include

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

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

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

    for(i=1;i<=r;i++)
    {
    if(i<=m)
    {
    for(s=1;s<=n-i+1;s++)
    {
    printf(" ");
    }

    printf("*");

    for(j=1;j<=2*i-3;j++)
    {
    printf(" ");
    }

    if(i!=1)
    {
    printf("*");
    }
    }
    else
    {
    k = i-m;

    for(s=1;s<=k;s++)
    {
    printf(" ");
    }

    printf("*");

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

    if(k!=n)
    {
    printf("*");
    }
    }

    printf("\n");
    }

    return 0;
    }

    ReplyDelete
  6. public class Simple{
    public static void main(String args[]){
    for(int i=1; i<=5; i++)
    {
    for(int j=1; j<=i; j++)
    {
    System.out.print("0");
    }
    System.out.print("\n");
    }
    }
    }

    ReplyDelete
  7. doing patterns using if conditions!! is it a bad programming practice?

    ReplyDelete