I'm having trouble with recursion!
If I have an array as: int a[] = {1, 2, 3, 4, 5};
and I want to display it on the screen like this:
1 2 3 4 5
I have to write : void PrintData(int a[], int n) to do that and using recursion!
How can I do that!
Please help me and thanks a lot!
lagvino_els
0
Newbie Poster
Recommended Answers
Jump to PostRather than predefining your array a[], why not use the integer value of n as the final output?
I don't like that you didn't post any code, but here's a hint:
for( i=0;i<n; ++i ) { a[i] = i+1; std::cout << a[i] << " "; }
All 4 Replies
Unimportant
18
Junior Poster
lagvino_els
0
Newbie Poster
Unimportant
18
Junior Poster
lagvino_els
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.