#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<cstdio>
#include<iostream>
#include<math.h>
using namespace std;
int main(){
double a,b;
a = b = 0;
while(scanf("%lf %lf",&a,&b) && !((a == 0) && (b == 0))){
double c,d;
c = d = 1.0;
int i ,j ;
for(i = a; i > a - b; i--)
c = c * (double)i;
for(j = b; j >= 1; j --)
d = d * (double)j;
printf("%.0lf things taken %.0lf at a time is %.0lf exactly.\n",a,b,c/d);
}
return 0;
}
1 刚开始自己没有想出来,后来看了别人的思路发现,给的100!也不过一百多位,而double可以支持三百多位(float32位),所以可以偷懒直接算
2 printf时double为lf
3 double在* 一个int时。要对int强制转换
本文介绍了一个使用C++实现的简单程序,该程序能够计算特定的组合数,并通过标准输入输出进行交互。文章展示了如何利用循环计算阶乘,以及在printf函数中正确使用double类型变量的格式说明符。此外,还分享了一些关于double类型运算的小技巧。
299

被折叠的 条评论
为什么被折叠?



