0

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 ;)

5
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by Narue
0

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

0
//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.

-1

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.....

Edited by Narue: Added code tags and formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.