inverting integers.

This is a discussion on inverting integers. within the C Programming forums, part of the General Programming Boards category; How can i write a program that accepts an integer stores it in a variable1.The program then reverses the digits ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    868
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 05:55 PM
  2. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 01: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21