I want to write a function that takes a positive integer as input and returns the leading digit in its decimal representation. For example, the leading digit of 234567 is 2
1
Expert's answer
2012-10-10T11:54:58-0400
#include <iostream> using namespace std;
int main (){ int a; cin>>a; while (a>9){ & a /= 10; } cout<<a<<endl; system("pause"); return 0; }
Comments
Leave a comment