返回整数从右边起某一指定位的数值(如int digitR(12345,2),返回4)

#include<iostream>
#include<cmath>
using namespace std;
int shuzhi(int a,int b)
{
	// 返回整数从右边起某一指定位的数值(如int digitR(12345, 2), 返回4)
	int d = pow(10, b);
	int c = (a%d) / pow(10, b - 1);
	return c;
}
int main()
{
	int a,b;
	cin >> a >> b;
	int c = shuzhi(a,b);
	cout << c << endl;
	return 0;
}

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐