首先可以使用地板函数对输入的数据进行取整操作,然后分情况进行取个位数字即可
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float n=0;
cin>>n;
if(n>=0&&n<10)
cout<<floor(n)<<endl;
else
{
int r=floor(n);
cout<<(r%10)<<endl;
}
return 0;
}

京公网安备 11010502036488号