Andy wrote:
>>   > --- In [email protected], "Andy" <andydick1111@> wrote:
>>   > >
>>   > > i have a c question....and i dont know how to do it....can anyone
>>   help?
>>   > >
>>   > 
>>   > Tell Me what is ur question ---- sunny singla
>>   >
>>
>>   Title: Pyramid of numbers
>>
>>   Generate the following "pyramid" of digits, using nested loops.
>>
>>   1
>>   232
>>   34543
>>   4567654
>>   567898765
>>   67890109876
>>   7890123210987
>>   890123454321098
>>   90123456765432109
>>   0123456789876543210
>>
>>   develop a formula to generate the appropriate output for each line.

Now that the other message is out of the way, on to actual help :)

The ability to develop a formula is a critical skill for a programmer - 
and one you have to pretty much develop on your own.  I'm not going to 
give you a direct answer BUT I will put you on the right track.

When I look at the above set of numbers, I see patterns.  Humans are 
good at spotting patterns.  The trick is to take any pattern you see and 
turn it into a formula.  Obviously, the first number, regardless of 
pyramid height, is 1.  The next row increments the outermost digit by 1 
AND the total number of digits displayed by 2.  Roughly halfway through 
the row, the number of digits start decreasing.  Digits wrap to 0 after 
9 (and vice versa during the decrease portion).

That is a lot to take in all at once.  So - I will show you this one 
last observation:

1
23
345
4567
56789

You can break this problem into two components:  Increasing and 
decreasing.  Once you have increasing figured out, decreasing is one 
extra for-loop.  In other words, write the code just for the increasing 
portion of the pyramid first.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.1
Get on task.  Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/

Reply via email to