write the algorithm to draw a sphere (Circle) , the function should have paramters
1. diameter (how many line)
2. character (use which character to draw)
eg, draw_sphere(10, '8') will produce:
the above is a sphere of 10 lines, which is drawn using the character "8"
could anyone help on this? im newbie in php, thanks in advance…
EDIT: I tried but vBulletin messes with the tabbing from post to render. Hopefully you can guess what it is intended to look like Mittineague
Well, there’s two variables for each line: the whitespace and the 8.
How can you figure out how much whitespace there should be and how many characters to draw?
Start out with what you should know: it should be as wide as it is tall. The width and the height are the same as the diameter. The length of a chord is the product of a function: http://www.mathopenref.com/chord.html and the whitespace is related to the diameter and the chord length.
But you should be able to do this. This is a a problem that high-school sophomores solve.
And how often in the real world are we faced with a problem such as drawing a sphere full of the digit “8”?
The original poster was asking this same question on other boards. The one where I found an explanation, if it is correct, is not as easy as some of you seem to think it is.
When I first got interested in computer programming, I talked to one of the programmers at the company I worked for. The most important tool a programmer can have, he said, is documentation. Nobody knows the answer to every problem. But someone with a brain and access to documentation can arrive at an answer (eventually). I’ll bet they don’t test for that.