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

Write the integers of an array vertically

P: 1
I know this is probably very simple but I really can't seem to understand how to write the integers vertically. For instance, there is an array that has 4 integers which are 9, 21, 63, and 501, the outcome would be the following

Expand|Select|Wrap|Line Numbers
  1.      9  2  5  6
  2.         1  0  3
  3.            1  
This is a small step of my program and probably the easiest but I can't understand how to do it :( Can someone please help me or guide me so I can finish my program
Feb 20 '13 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 10K+
P: 12,421
The basic algorithm would look like this:

1) Find longest element in the array.
2) Loop from 1 to length of longest element.
3) Nest a loop to loop through each element of the array.
4) Append the digit at position in that element of the array if it exists, otherwise append a space.
5) End the inner loop
6) Append a new line.
7) End outer loop.
8) Output results.
Feb 20 '13 #2

Post your reply

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