Advertisement
Abelsor

Invertir Digito (Optimizado)

Mar 20th, 2023
598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. // Invertir Digitos (OPTIMIZADO)
  2.  
  3. #include<iostream>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int n;
  9.     cin>>n;
  10.  
  11.     int digito = 0;
  12.     int num_invertido = 0;
  13.  
  14.     while(n>0){
  15.         digito = n%10;
  16.         num_invertido = num_invertido*10 + digito;
  17.         n = n/10;      
  18.     }
  19.  
  20.     cout<<"Invertido: "<<num_invertido<<endl;
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement