Search C Program | nimishsoft@gmail.com

Number Pattern - 45

*000*000*
0*00*00*0
00*0*0*00
000***000

int main()
{
  int i,j,k;
  for(i=1;i<=4;i++)
  {
    for(j=1;j<=9;j++)
    {
      if(j==i || j==5 || 10-j==i)
        printf("*");
      else
        printf("0");
    }
    printf("\n");
  }
  return 0;
}


Related Links:
- More Number Pattern Programs
- Star Pattern Programs in C
- Alphabet Pattern Programs in C
- Series Programs in C


7 comments:

  1. it can also be the solution bro :P
    #include
    int main()
    {

    int i,j;
    int p,c1,c2;
    p = 1;
    c1 = 1;
    c2 = 9;
    for(i=1;i<=4;i++)
    {

    for(j=1;j<=9;j++)
    {
    if(i==p&&(j==c1||j==c2||j==5))
    printf("*");
    else
    printf("0");
    }
    p++;
    c1++;
    c2--;
    printf("\n");
    }
    return 0;
    }

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

    ReplyDelete
  3. #include

    int main()
    {
    int r,i,j;

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

    for(i=1;i<=r;i++)
    {
    for(j=1;j<=i-1;j++)
    {
    printf("0");
    }

    printf("*");

    for(j=1;j<=r-i;j++)
    {
    printf("0");
    }

    printf("*");

    for(j=1;j<=r-i;j++)
    {
    printf("0");
    }

    printf("*");

    for(j=1;j<=i-1;j++)
    {
    printf("0");
    }

    printf("\n");
    }

    return 0;
    }

    ReplyDelete
    Replies
    1. What if the no of rows are given in the command line?

      Delete
  4. why you use 9 inside "j" loop?

    ReplyDelete