First digit in product of an array of numbers | C ++ implementation to find first digit of a single number ; Keep dividing by 10 until it is greater than equal to 10 ; driver function
#include <bits/stdc++.h> NEW_LINE using namespace std ; int firstDigit ( int x ) { while ( x >= 10 ) x = x / 10 ; return x ; } int main ( ) { cout << firstDigit ( 12345 ) << endl ; cout << firstDigit ( 5432 ) << endl ; }