int leadDigit(int n)
{
int m[9];
int k = 100'000'000;
int i;
for (int i = 7; i >=0; i--)
{
m[i] = n % k / (k / 10);
k /= 10;
}
for ( i = 7; i>=0;i--)
{
if (m[i] == 0)
{
m[i] = m[i - 1];
}
else
{
return m[i];
}
}
}
int main()
{
system("cls");
int k;
cout << "Enter Number : ";
cin >> k;
cout<<"The leading digit of " <<k<<" is "<<leadDigit(k) << endl;
return 0;
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น