直接上code:
#include <stdio.h>
#include<math.h>
#include<iostream>
using namespace std;
int digit(int num, int k);
int num;
int k;
int main ()
{
cout << "please enter your number" << endl;
cin >> num;
cout << "plase enter the number of the site you wanted" << endl;
cin >> k;
digit(num, k);
return 0;
}
int digit(int num, int k)
{
if (num == 0)
{
cout << "you've input the wrong number" << endl;
}
else if(k==0)
{
cout << "the number of site you wanted must be with value" << endl;
}
else
{
int temp;
temp=num % ((int)pow(10,k));
if (temp > 10)
{
temp = temp / 10;
}
cout << "the site fo the number you wanted is:" << temp << endl;
}
return 0;
}
测试结果截图: