Finding the first and last digits of a number.

PHOTO EMBED

Sat Jan 04 2025 05:32:57 GMT+0000 (Coordinated Universal Time)

Saved by @KKOMAL

#include <iostream>
using namespace std;
int main() {
        int a;
        cout << "enter a number: ";
        cin >> a;
         cout << "Last digit: " << a%10;
        for (a; a >= 10; a /= 10) {
            
        }
        cout << "\nFirst digit: " << a;
        
    return 0;
}
content_copyCOPY