0

Alright, so you have input that looks like this:

      1 6
      2 3 4
      1 8
      3 4 7 2


1st # represents the number of dimensions of the array
2nd # = the # of elements in the array.
3rd # = the rows of the array (index)
4th # = columns

Write a segment of code that will print out the indices of the array. For example, the output of the 2nd line should look like:

  00
  01
  02
  03
  10
  11
  12
  13
  20
  21
  22
  23

I hope that makes sense. I understand how to write the code without recursion. It's just a matter of for loops and cout statements but I can't figure out how to use recursion. For the simplest case, which would be a 1-dimensional array, we'd write out the code but for the second simplest case we have to use recursion which will then work for the next 3rd and 4th etc cases.

1
  • 1
    I'm not sure if it is clear what you are asking. Could you rephrase your problem? Commented Jun 20, 2015 at 3:21

1 Answer 1

1

One way to do it recursively is to write a function that takes a number p and a string of numbers like the ones in the input file. The function prints out results as you describe, but uses p as a prefix. So f(99, 1 4) would print:

990
991
992
993

Is that enough of a hint, or should I go a little farther?

Sign up to request clarification or add additional context in comments.

2 Comments

Hmm I'm still confused. Not sure what you mean by using a string of numbers. Can you please elaborate? Thank you =)
@helpme99: A sequence of numbers, like [1, 4], or [2, 3, 4]. I'm suggesting a function that takes two arguments; the first is a number and the second is a sequence of numbers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.