Hi can you pls help me how this program containing a function that accepts a 5-digit numbers & returns the digit in reverse.
like:
Enter 5-digit number: 13569
Reversed: 96531

thankyou ;)

Recommended Answers

All 4 Replies

Instead of flipping the number, save the number in reverse so it can be automatically printed in the reverse order.

//Here's a function that does the job.
//Parameter n is the number to be reversed.
//This function returns the reversed number.
//Actually this function can reverse any digit numbers.

int reverse(int n)
{
  int rev = 0; //this variable stores the reverse of n
  while(n > 0)
  {
    rev = (rev * 10) + (n % 10);
    n /= 10;
  }

  return rev;
}

By careful examination of the code it will be clear how it works.

try this one:

#include<stdio.h>
main()
{
    int n,r;
    scanf("%d",&n);
    while(n!=0) {
        r=n%10;
        printf("%d",r);
        n=n/10;
    }
    return 0;
}

I hope this one works.....

I hope this one works.....

If you test code before posting it, you wouldn't have to hope.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.