How to get the last digits of int number in C++

1 Answer

0 votes
#include <iostream>  

int main() {  
    int n = 8405961, swapn;  
    std::cout << "n: " << n << "\n";  
 
    int lastdigit = n % 10;
    std::cout << "lastdigit: " << lastdigit << "\n";  

    return 0;
}  
  
  
  
  
/*
run:
  
n: 8405961
lastdigit: 1
  
*/

 



answered Jan 15, 2021 by avibootz

Related questions

1 answer 164 views
1 answer 139 views
1 answer 228 views
1 answer 181 views
2 answers 224 views
1 answer 171 views
...