# Thread: Reverse a five digit number in C

1. ## Reverse a five digit number in C

Create program with following transformation:
1- Reverse a five digit number
you can only use printf, scanf, arithmetic operators, comparison
operators and selection statements i.e. if and if‐else.

2. You can treat the number as a string. Set proper memory constraints on the string variable. Set up a looping structure to print the string array in reverse order.

3. Welcome to the forum, Aamir!

Post up your code, and tell us what has you stumped with this problem.

4. u can only use integers and floats with basic mathematical operands , comparison operations and selection statements if and if-else without using loops and strings

5. You can do this with the modulus operator then.

6. Well, it's a little awkward, but right off I'd think some int variables like one, two, three, etc., could be used to hold the digits as you peeled them off the original number:

int one, two, three, num=345;
one=num% 10;
num /10;
two=num%10
num /10
kind of logic.

What method has your instructor suggested for this assignment? What have you tried?

7. Post up what code you have thus far.

This isn't a homework forum, man...

8. Actually I had used this code and it also worked but everyone is using this code. I wanted some other way to do it .please.

Code:
```#include<stdio.h>
int main()
{
int a,b,c,d,e,f,g,i,h,j,sum;
float o,p,q,r;

printf("Enter the five digit number\n");
scanf("%d",&a);

b=a%10;
c=a/10;
d=c%10;
e=c/10;
f=e%10;
g=e/10;
i=g%10;
j=g/10;

printf("%d%d%d%d%d\n",b,d,f,i,j);

sum=b+d+f+i+j;
printf("Sum of digits = %d",sum);

return 0;
}```

9. Without using loops, your options are very limited for doing this. I believe my idea of naming and using variables (posted above), was "cleaner" than your last posted code, but it still amounts to the same basic logic.

There are other ways to do this, but none of them are simple enough.

Without using loops, your options are very limited for doing this. I believe my idea of naming and using variables (posted above), was "cleaner" than your last posted code, but it still amounts to the same basic logic.

There are other ways to do this, but none of them are simple enough.
like???

11. Working with the individual bits in the number, and using the base 2 number line.

Using recursion

Oh! What about using sscanf() ? That's the string scanning function sister of scanf(). That would be easy.

12. 5-digit number you say? You can do this: 99999 - number

13. Code:
``` 99999
-12345
======
87654```
?

14. I was just joking! I think i saw it somewhere.