By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,118 Members | 1,133 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,118 IT Pros & Developers. It's quick & easy.

asterisk algorithm

joewin
P: 2
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**
Mar 2 '17 #1
Share this Question
Share on Google+
2 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
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++?
Mar 2 '17 #2

dev7060
100+
P: 103
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 *.
Mar 3 '17 #3

Post your reply

Sign in to post your reply or Sign up for a free account.