Advertisement
brainuser5705

reverse number in C

Apr 24th, 2021
56
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2.  
  3. int main(void){
  4.     int num;
  5.     printf("What number do you want to reversed? ");
  6.     scanf("%i", &num);
  7.  
  8.     int final_num = 0;
  9.  
  10.     while (num != 0){
  11.         int digit = num % 10;
  12.         final_num *= 10;
  13.         final_num += digit;
  14.  
  15.         num /= 10;
  16.     }
  17.  
  18.     printf("The reversed number is %i.", final_num);
  19.  
  20.     return 0;
  21. }
Advertisement
RAW Paste Data Copied
Advertisement