1 #include <stdio.h> 2 float fac(int a)//阶乘 3 { 4 if(a==0) 5 return 1; 6 else 7 return a*fac(a-1); 8 } 9 int main() 10 { 11 int t,i,num; 12 float p[50]={0,0,1}; 13 scanf("%d",&t); 14 i=3; 15 while(t--) 16 { 17 scanf("%d",&num); 18 for(;i<=num;i++) 19 p[i]=(i-1)*(p[i-1]+p[i-2]); 20 printf("%.2f%%\n",p[num]*100/fac(num)); 21 } 22 return 0; 23 }
时间: 2024-10-29 19:11:54