fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int num = 4562; // Original number
  5. int reversed = 0;
  6.  
  7. printf("Original number: %d\n", num);
  8.  
  9. while (num != 0) {
  10. int digit = num % 10; // Extract the last digit
  11. reversed = reversed * 10 + digit; // Append the digit to the reversed number
  12. num = num / 10; // Remove the last digit
  13. }
  14.  
  15. printf("Reversed number: %d\n", reversed);
  16.  
  17. return 0;
  18. }
  19.  
Success #stdin #stdout 0s 5264KB
stdin
Standard input is empty
stdout
Original number: 4562
Reversed number: 2654