C语言编程>第八周 ⑦ 编写函数fun,它的功能是:根据以下公式求的值,结果由函数值带回。m与n为两个正整数且要求m>n。

例题:编写函数fun,它的功能是:根据以下公式求的值,结果由函数值带回。m与n为两个正整数且要求m>n。
在这里插入图片描述

例如:m=10,n=5时,运行结果为252.000000。
请勿改动主函数main与其它函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

代码如下:

#include
#include
float fun(int m,int n)
{
     
	float result,temp=1.0;
	int i;
	for(i=1;i<=m;i++)
		temp=temp*i;
	result=temp;
	for(temp=1.0,i=1;i<=n;i++)
		temp=temp*i;
	result=result/temp;
	for(temp=1.0,i=1;i<=m-n;i++)
		temp=temp*i;
	result=result/temp;
	return result;
}
main()
{
     
	FILE*out;
	printf("Result=%f\n",fun(10,5));
	out=fopen("outfile.dat","w");
	fprintf(out,"%f",fun(12,6));
	fclose(out);
}

输出运行窗口如下:
C语言编程>第八周 ⑦ 编写函数fun,它的功能是:根据以下公式求的值,结果由函数值带回。m与n为两个正整数且要求m>n。_第1张图片

越努力越幸运!
加油,奥力给!!!

你可能感兴趣的:(C语言程序设计,c语言,程序设计,编程语言,代码规范,计算机二级C语言考试上机题)