1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

digit reverse in C

Discussion in 'C' started by soulemane, Apr 30, 2008.

  1. soulemane

    soulemane New Member

    Joined:
    Nov 12, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    All my greetings to everyone.
    With a lot of respect to all members of this forum ,please i'm struggling since already many days to solve this problem.In fact how can we reverse a number (e.g 12345 to 54321)using only looping without array nor pointer or other advanced codes.Also for a number like 1000 it must be 1 inspites of 0001.
    thank you for your support Assalam :thinking: :thinking:
     
  2. SpOonWiZaRd

    SpOonWiZaRd Know what you can do.

    Joined:
    May 30, 2007
    Messages:
    747
    Likes Received:
    8
    Trophy Points:
    0
    Occupation:
    Network Engineer/Programmer
    Location:
    South Africa
    Hello!!!!!!!!!!! I do not know that but I am sure pradeep will know.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    Moved to C-C++ forum
     
  4. asadullah.ansari

    asadullah.ansari TechCake

    Joined:
    Jan 9, 2008
    Messages:
    356
    Likes Received:
    14
    Trophy Points:
    0
    Occupation:
    Developer
    Location:
    NOIDA
    Here i am just giving you an idea. Solve it by making it efficient and accurate.

    Code:
    int nDigit=1,result=0;
    while(n>0)
    {
      n=n/10;
      ++nDigit;
    }
    for(int i=0; i<nDigit;++i)
    {
       result = result+ n%10 +pow(10 , nDigit-i);
       n = n/10;
    }
     
    Last edited by a moderator: May 6, 2008

Share This Page