asterisk algorithm

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joewin
    New Member
    • Feb 2017
    • 2

    asterisk algorithm

    Guys, help me.
    Give me some hints on how to do this program . . .
    a program that will print an asterisks and zeroes one-at-a-time and will to print like the following pattern.

    **0**

    *0*0*

    0*0*0

    *0*0*

    **0**
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You could always:

    printf("**00**\ n");

    and use a separate printf for each pattern.

    If you can't do this, then there must be some required things left out of your problem description

    Are you using C or C++?

    Comment

    • dev7060
      Recognized Expert Contributor
      • Mar 2017
      • 656

      #3
      Yes, the above pattern can be printed using output statements. However, you may also use loops for this. Try to mention your approach/code you are using.

      Some idea: In the 2nd line, you can observer that 0s are present at even places [*2*4*] and in the 3rd line at odd places [1*3*5] etc. So, declare an array of length 5 and use the modulus operator to check for even and odd places and assign the value of 0 to them, the rest of the array can contain *.

      Comment

      Working...