int i,N,K,K1,K2,K3,K4,K5;//////K1~K5分别为输出的K值
int Sum,Size,Ws;
N = 6;/////////随便设置的N值
Sum = N;
K = 3;/////////随便设置的K值
for(i=N-1;i>0;i--)
{
Sum *= i;////阶乘
}
switch(K-1) {
case 0:
Size = 0;
break;
case 1:
Size = 10;
break;
case 2:
Size = 100;
break;
case 3:
Size = 1000;
break;
case 4:
Size = 10000;
break;
case 5:
Size = 100000;
break;
default:
break;
}
if(N-11>0.0001)
{
AfxMessageBox("阶乘数太大,\n请重新输入!");
return;
}
if(fabs(K)>5 || K==0)
{
AfxMessageBox("位数不符合要求,\n请重新输入!");
return;
}
if(fabs(K)*Size-Sum>0)
{
AfxMessageBox("超过n!的位数,\n请重新输入!");
return;
}
CString str;
str.Format("%d",Sum);
Ws = str.GetLength();
switch(Ws) {
case 0:
Size = 0;
break;
case 1:
Size = 10;
break;
case 2:
Size = 100;
break;
case 3:
Size = 1000;
break;
case 4:
Size = 10000;
break;
case 5:
Size = 100000;
break;
case 6:
Size = 1000000;
break;
case 7:
Size = 10000000;
break;
case 8:
Size = 100000000;
break;
/////////////////////N不超过11最大位数为8
default:
break;
}
if(K>0)
{
if(Size/100000 >1)
Sum %= (Size/(Size/100000));
K5 = Sum/10000;
K4 = (Sum%10000)/1000;
K3 = ((Sum%10000)%1000)/100;
K2 = (((Sum%10000)%1000)%100)/10;
K1 = ((((Sum%10000)%1000)%100)%10)/1;
}