Thread: inverting integers.

  1. #1
    in the shadows
    Join Date
    Oct 2005
    Location
    nairobi,kenya
    Posts
    9

    Unhappy inverting integers.

    How can i write a program that accepts an integer stores it in a variable1.The program then reverses the digits in the integer and stores them in another variable2,then outputs both integers?
    Example:
    you enter 387 the value is reversed to 783.
    NOTE:The new value MUST be stored in variable2 before it is output.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You've gotta start posting your initial efforts with your questions!
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    in the shadows
    Join Date
    Oct 2005
    Location
    nairobi,kenya
    Posts
    9
    my "initial efforts" resulted in nothing but syntax errors so dont have initial efforts that i can actually speak of,any ideas?

  4. #4
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Show us the code, show us the syntax errors, we'll help you out. We do not do homework for you, it defeats the purpose of you being set homework.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > my "initial efforts" resulted in nothing but syntax errors
    Well the first step at least is to finish off all the input and output
    Code:
    printf ( "Enter a number\n" );
    scanf( "%d", &inputValue );
    outputValue = inputValue;
    printf( "The result is %d\n", outputValue );
    Once you've done that, then you can work on replacing the outputValue = inputValue; with the actual code which does what you want.

    Hint: Look up the / and % operators
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    in the shadows
    Join Date
    Oct 2005
    Location
    nairobi,kenya
    Posts
    9
    but won't outputvalue=inputvalue only dublicate the inputvaluei.e the will give interger that you enterd?

  7. #7
    in the shadows
    Join Date
    Oct 2005
    Location
    nairobi,kenya
    Posts
    9
    Code:
    int main()
    {
    int i,j;
       printf("Enter an interger: ");
     scanf("%d",i);
    Ok give me a hint:
    what kind of code am looking to make?

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > but won't outputvalue=inputvalue only dublicate the inputvaluei.e the will give interger that you enterd?
    Exactly, but until you can prove to yourself that you can reliably input a value and output it again unchanged, there is no way that you can progress onto the next bit. Even if you stumble on the correct answer you won't know that you have if the input is broken to start with.

    Try printing the result of inputValue % 10
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    This person's posts just go to show that no matter where in the world you are, there will always be lazy people who want everything done for them without any effort on their part.


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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  2. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 02:24 PM
  3. Integers into array.
    By livestrng in forum C Programming
    Replies: 10
    Last Post: 10-29-2008, 11:35 PM
  4. Pass by reference
    By jrice528 in forum C++ Programming
    Replies: 4
    Last Post: 10-30-2007, 01:02 PM
  5. Replies: 6
    Last Post: 08-04-2003, 10:57 AM