Thread: Display Reverse Number, no strings or arrays

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    1

    Display Reverse Number, no strings or arrays

    I'm learning C at my local university.
    For homework assignment 3, I wrote a program that requests a
    positive integer from the user, then replies,
    "your number is ___"
    "it has ___ digits"
    "the reverse number is: ___"
    with all the relevent information filled in and it works well.
    The assignement is due next week.

    The problem is: today I received an email saying I'm not allowed
    to use an array or a string in writing the program!
    I can't figure out how I can possibly get the reverse number to
    the screen without using an array or a string.
    (Only the reverse number is stumping me; both echoing the number
    and giving the number of digits I can do)

    Please tell me how I can do this.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Use modulus (%) 10 to get the last digit, divide by 10 to remove the last digit.
    Code:
    int Reverse(int Num)
    {
       int Result = 0;
    
       while(Num != 0)
       {
          Result *= 10;
          Result += (Num % 10);
          Num /= 10;
       }
    
       return Result;
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Way to go. Another person who does absolutely nothing and gets a working answer.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You know. Normally I couldn't care less about getting red candy. But today I make an exception:
    Code:
    [] 	Display Reverse Number,...  	12-07-2004 12:41 AM  	Do you ever actually .help. anyone?! 傻瓜!
    Alright, twenty of you people could consecutively hit me with red and it still wouldn't make any difference. But let's look at this thread shall we?

    Quote Originally Posted by John Smith
    I'm learning C at my local university.
    For homework assignment 3, I wrote a program that requests a
    positive integer from the user, then replies,
    "your number is ___"
    "it has ___ digits"
    "the reverse number is: ___"
    with all the relevent information filled in and it works well.
    The assignement is due next week.

    The problem is: today I received an email saying I'm not allowed
    to use an array or a string in writing the program!
    I can't figure out how I can possibly get the reverse number to
    the screen without using an array or a string.
    (Only the reverse number is stumping me; both echoing the number
    and giving the number of digits I can do)

    Please tell me how I can do this.
    Right. Now first off, without posting any code at all, the OP says they have created a program which reverses a number using a string. That's fine.

    Next, they say they can't use strings. That's fine too. Which leaves us with them saying they don't know how to reverse a number without using strings, and could we "Please tell me how I can do this."

    First off: All they had to do is search the forum, and they would have found their answser. Reversing a number is posted here all the time.

    So we know for a fact that they didn't search the forums like they were supposed to. For you see, when I search using two words "reverse number" I get a bunch of stuff.

    Now that took me all of 2 minutes to go through the two pages of search results and pick out ones that would match the question of this thread. There are doubtless more scattered around, and were one actually to take the time and try oh, I don't know, maybe a few more key words, I'm sure they'd get plenty if those four weren't enough.

    Now let's examine that second link. Go on click it.

    What is the first reply to that thread? I'll give you a hint: IT'S THE SAME REPLY AS THIS THREAD'S FIRST ONE.

    So what do we have now? We have one person who consistantly gives the full answer to homework, making not attempt to even mask it. This isn't helping anyone learn anyone. For that matter, let's cover the forum rules:
    Announcement: Homework

    Homework Policy:

    The purpose of these board is not for other people to do your homework for you. Try things out work on your own, homework has a purpose. If you still have trouble with a specific piece of code or concept please feel free to ask. But please do not ask people to do your entire homework for you, it simply annoys people most of the time.

    For an example check out this thread written by Prelude. Thanks Prelude.

    If you are looking for someone to do an entire problem for you, we recommend that you use the site's Ask an Expert service. Please note: We strongly discourage people from cheating. It is there for personal and non-graded problems that are not answered on the message boards.

    If you have any questions about what is approprate, or anything else, please E-mail or PM me and I'll be happy to answer them.

    Thank you

    Kermi3
    Lead Moderator
    See that?

    There needs to be a corollary to the above: STOP DOING EVERYONE'S HOMEWORK FOR THEM.

    Magos, I didn't give you red candy for your reply. I don't know if you gave me it, because you didn't have the balls to sign your red marks. As far as the red goes, I don't care.

    To whoever actually did leave it, how about you pull your head out of your ass long enough to look at how this forum operates for a second. Go read the rules again. We are not here to do your homework for people. We are here to assist people in finding the answer. Oh, and as to "do I ever help people"? How about you go visit the third link of the bunch I posted. THAT is how you answer this question. I explained how to do it. I didn't do it for them.

    On second thought, Magos. Enjoy your candy.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    I believe this is a breakthrough for Cboard.

    No one has had the courage to put the people down who divulge answers. I'm not saying no-one has, though Quzah seems to have grasped the full story, leaving no footholes or open doors to bash. Looks like we have our hero!

    I agree with what Quzah said. I don't see anything logical with giving him a negative reputation for doing the right thing. Though, I guess it's the price we pay. In this case, I'm giving Quzah some green candy for his heroic actions.

    I have a question. May not be the perfect time, but it can't hurt to ask. Is there a rule where homework questions are not allowed to be answered and/or if there is a punishment for those that divulge such information?


    - Stack Overflow
    Last edited by Stack Overflow; 12-07-2004 at 06:11 PM. Reason: Typo
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

  6. #6
    Registered User
    Join Date
    Oct 2004
    Posts
    63
    I agree with Quzah. If I have any problem with C++, I want to work through it myself....I come here for a pointer towards the right direction. Giving somebody the answer doesn't help them understand it.

    I gave you some green candy Quzah for standing up for it, but I'm not sure if it went through (I kinda mashed the backspace/enter key by accident)
    -Webmaster-
    http://www.koaworld.com
    Pr0gr4m|\/|1Ng n00b

  7. #7
    Registered User
    Join Date
    Apr 2004
    Posts
    210
    Generally I think you have a slight tendency to overreact, Quzah. Like in the discussion we had about that poor guy who posted three #includes without code tags, if you remember.
    Anyways, lately I stumbled across several homework-threads of this kind and I got to agree with you (green dots ). Helping someone so he can help himself is fine. Doing his work is not.

    I guess I'm calling for those red dots now, but I can't help it. I don't think stuff like this is approriate either:

    Quote Originally Posted by Quzah
    I don't know if you gave me it, because you didn't have the balls to sign your red marks. As far as the red goes, I don't care.

    To whoever actually did leave it, how about you pull your head out of your ass long enough to look at how this forum operates for a second.
    main() { int O[!0<<~-!0]; (!0<<!0)[O]+= ~0 +~(!0|!0<<!0); printf("a function calling "); }

  8. #8
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Gee, sorry!! The rules states nothing about helping, only asking. If he's asking for help which doesn't increase his learning then that's his problem. I'm not his parent nor teacher, just a guy enjoying to code. If you have such a zero-tolerance on this, then please explicitly state it in the homework sticky.

    And I haven't touched your reputation if that's what you're implying (the candy-thingy)....
    Last edited by Magos; 12-08-2004 at 05:32 AM.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  3. help understanding arrays of strings!
    By smoking81 in forum C Programming
    Replies: 18
    Last Post: 02-23-2008, 04:24 AM
  4. help with a source code..
    By venom424 in forum C++ Programming
    Replies: 8
    Last Post: 05-21-2004, 12:42 PM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM