Input an integer number from the keyboard and print out the reverse of that number


SUBMITTED BY: Guest

DATE: Nov. 5, 2013, 5:45 p.m.

FORMAT: C++

SIZE: 614 Bytes

HITS: 920

  1. // PURPOSE : Input an integer number from the keyboard and print out the reverse of that number
  2. #include <stdio.h>
  3. int main()
  4. {
  5. int n;
  6. int backup_copy_of_n;
  7. int digit;
  8. int reverse = 0;
  9. printf("\n Please enter a positive integer : ");
  10. scanf_s("%d", &n);
  11. backup_copy_of_n = n;
  12. while (n != 0)
  13. {
  14. digit = n % 10;
  15. reverse = (reverse * 10) + digit;
  16. n = n / 10;
  17. }
  18. printf("\n The reverse number for %d is %d.", backup_copy_of_n, reverse);
  19. getchar();
  20. getchar();
  21. return 0;
  22. }

comments powered by Disqus