This is my version.
I've used while function and two if functions. The second if command check if right_digit variable is negative (i know that it is negative when the number variable is negative) and print a "-" sign at the end.
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
@autoreleasepool {
// Program to reverse the digit of a number
int number, right_digit;
NSLog(@"Enter your number");
scanf(" %i", &number);
while (number != 0) {
right_digit = number % 10;
if (right_digit < 0) {
NSLog(@"%i", -right_digit);
}
else
NSLog(@"%i", right_digit);
number /=10;
}
if (right_digit < 0) { // I know if "my number" is negative, for XCode right_digit is negative
NSLog(@"-");
}
}
return 0;
}
Result:
2012-04-13 18:57:07.117 Esercizio5Cap6[34221:707] Enter your number
-5678
2012-04-13 18:57:11.239 Esercizio5Cap6[34221:707] 8
2012-04-13 18:57:11.240 Esercizio5Cap6[34221:707] 7
2012-04-13 18:57:11.241 Esercizio5Cap6[34221:707] 6
2012-04-13 18:57:11.242 Esercizio5Cap6[34221:707] 5
2012-04-13 18:57:11.242 Esercizio5Cap6[34221:707] -
Program ended with exit code: 0