![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Sep 2005
Posts: 5
Rep Power: 0
![]() |
c++ recursion question
I am a beginning programmer and I am having difficulty grasping the concept of recursion........Here's what I am talking about:
#include <iostream> using namespace std; void write(int n); int count=0; int main () { write(3069); return 0; } void write (int n) { if(n>1){ write(n/10); cout << n%10; } } /* RESULTS: 3069 */ This is just a simple example that will illustrate my question....When tracing this programming, write enters with 3069, then it sends it 306, then it sends it 30, then it sends write 3.......my question is how come (when you mod it by 10) it prints out the number in the same order. I guess what I am really asking is how does the recursive calls sort of stay "suspended" without anything happening to it....I guess what I am asking is for someone explain to me how to properly trace this......Thank you for your time. Your response is appreciated! |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
YOU should spend some time reading the forum's FAQ/Rules and a "How to Post..." thread. Anything less is rude to those from whom you are seeking help. Put your code in tags. Thanks for your time, your appropriate response will be appreciated.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Sep 2005
Posts: 5
Rep Power: 0
![]() |
YOU are right. I am so very sorry and I send my deepest apology's that my thread isn't properly formatted. I should have known better than to ask for help because I am only trying to better myself. I hope that not everyone has the same attitude as you. Yes, it may be true that I should have read the "how to post forum," but the fact of the matter is I have more things to do with my time than to sit and read such nonsense. I refuse to return to this forum, and I hope that when I attain my degree, I don't become as rude as you. Thank you for your time.
|
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
You should check my other responses before you accuse me of not being helpful. YOU are being rude. This is a place to get help. The least you can do is check the rules of the community you are appealing to. If you have better things to do then read our "nonsense" guidelines, I assure you, WE have better things to do than help a big-headed, egoistical dummy.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#5 | |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4
![]() |
Quote:
Those that could potentially help you have more things to do with their time then help an ungrateful poster who seeks the knowledge of others twho ask nothing in return. EDIT: Oops, I guess you felt the same way DaWei :p
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: Sep 2005
Posts: 5
Rep Power: 0
![]() |
dummy eh? I was being rude, but that is only becuase you were being rude... I never called you any names becuase I will not stoop that low. However, the nice thing to do would have been to answer my question and say next time, why don't you read our "how to post" article so you can fit in as a member of this community.
|
|
|
|
|
|
#7 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
You want free advice. You don't want to pay the price of being civil enough to check the culture before you get your freebies. You want to do it "next time." With your attitude, you need to go back to mama and get your sugar teat and you pat on the ass for being a good little boy. You won't get it in the real world, with your attitude. Have your hand measured for a mop handle. If you don't change, you'll be a janitor.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Sep 2005
Posts: 5
Rep Power: 0
![]() |
hahaha.....wow....what a waste of time......im outta here......
|
|
|
|
|
|
#9 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
You keep promising, but you don't deliver....
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#10 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
browning_man, accepting correction is sometimes hard, just look at all those disobedient children out there. But grow up, and listen to what is said. You got a lot to learn, as do we all.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|