Reversing the digits: do while loop : Do While « Statement « C Tutorial






#include <stdio.h>

int main(void)
{
  int number = 123;
  int rightMostNumber = 0;
  int temp = 0;

  temp = number;

  do
  {
    rightMostNumber = 10*rightMostNumber + temp % 10;
    temp = temp/10;
  } while (temp);

  printf ("\nThe number %d reversed is  %d\n", number, rightMostNumber );
  return 0;
}
The number 123 reversed is  321








6.8.Do While
6.8.1.The do...while loop
6.8.2.Reversing the digits: do while loop
6.8.3.Read number in a range
6.8.4.Nest for loop inside do while loop