How to select the last three digits from a 6-digit number in C++

1 Answer

0 votes
#include <iostream>

int main() {
    int num = 123456;   // Example 6-digit number
    int lastThree = num % 1000;  // Keeps last 3 digits
    
    std::cout << "Last three digits: " << lastThree << std::endl;
}


 
/*
run:
 
Last three digits: 456
 
*/

 



answered Nov 25, 2025 by avibootz
...