i'm having the most difficulty writing this program (perhaps it's due to my week long hiatus from programming to try to set up a dual boot config)... here is the question and my code pasted below:
5. Exercise 3 in Chapter 4 asked you to write a program that displays a two-digit number with its digits reversed. Generalize the program so that the number can have one, two, three, or more digits. H*I*N*T: Use a 'do' loop that repeatedly divides the number by 10, stopping when it reaches 0.
here is the code from Exercise 3 (and the code for #5 below that):
EX 3 -
/* SEC4.1 EX3 */
/* DATE: 07-21-02 */
#include <stdio.h>
int main()
{
int one, two;
printf("Enter a 2-digit number: ");
scanf("%d", &one);
two = one % 10;
one = one / 10;
printf("The reversal is: %d%d\n",two, one);
return 0;
}
--------------------------------------------
# 5 -
/* SEC6.2 EX5 */
/* DATE: 08-01-02 */
#include <stdio.h>
int main()
{
int m, n, o, p, q ;
printf("Enter a number: ");
scanf("%d", &n);
do {
m = n % 10;
o = n / 10;
p = o % 10;
q = o / 10;
printf("The reversal is: %d%d\n", m, p, q);
break;
} while (n > 0);
return 0;
}