How to subtract the last digit of a number from the same number in C++

1 Answer

0 votes
#include <iostream>  

int main() {  
    int n = 8405796;  
       
    std::cout << n << "\n";  

    n = n - n % 10;
         
    std::cout << n;  
       
    return 0;
}  
   
   
   
   
/*
run:
   
8405796
8405790
   
*/

 



answered Jan 15, 2021 by avibootz

Related questions

1 answer 147 views
2 answers 196 views
3 answers 264 views
2 answers 263 views
1 answer 193 views
...