编写函数fun(),它的功能是;根据以下公式求p的值,结果由函数值带回。m与n为两个正数且要求m>n。
P=m!/n!(m-n)!),例如:m=12,n=8时,运行结果为495.000000。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <stdio.h>
float fun (int m, int n)
{
}
main()
{
clrscr() ;
printf ("p=%f\n", fun (12,8) ) ;
}
编写函数fun(),函数的功能是:根据以下公式计算s,计算结果作为函数值返回;n通过形参传入。
S=1+1/(1+2)+1/(1+2+3)+…+1/(1+2+3+…+n)
例如:若n的值为11时,函数的值为1.833333。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <stdio.h>
include <string.h>
float fun(int n)
{
}
main()
{
int n;
float s;
clrscr();
printf("\nPlease enter N: ");
scanf("%d",&n);
s=fun(n);
printf("The result is:%f\n " , s);
}
下列给定的程序中,函数fun()的功能是:求出以下分数序列的前n项和。
2/1,3/2,5/3,8/5,13/8,21/13,…
其值通过函数值返回main()函数。例如,若输入n=5,则应输出8.391667。
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
[试题源程序]
include<stdio.h>
include<conio.h>
double fun(int n)
{
int a=2, b=1, c, k;
double (1) ;
for(k=1; k<=n; k++)
{
s=s+1.0 *a/b;
c=a; a+= (2) ; b=c;
}
return(d);
}
main()
{
int n=5;
printf("\nThe value of function is: %1f\n", (3) );
}
请编写函数fun(),该函数的功能是:计算并输出
S=1+(1+20.5)+(1+20.5+30.5)+…+(1+20.5+30.5+…+n0.5)
例如,若主函数从键盘给n输入20后,则输出为
s=534.188884。
注意;部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仅在函数fun 的花括号中填入所编写的若干语句。
试题程序:
include <math. h>
include <stdio. h>
double fun(int n)
{
}
main()
{
int n;
double s;
printf("\n\nInput n: ");
scanf ("%d", &n);
s=fun (n)
printf ("\n\ns=%f\n\n", s);
}
请编写函数fun(),该函数的功能是:计算n门课程的平均分,计算结果作为函数值返回。
例如x有5门课程的成绩是90.5,72,80,61.5,55,则函数的值为71.80。
注意:部分源程序给出如下.
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
float fun (float *a, int n)
{
}
main ()
{
float score[30]=(90.5,72,80,61.5,55},
aver;
aver=fun(score, 5);
printf("\nAverage score is: %5.2f
\n",aver);
}
请编写一个函数fun(),它的功能是:求出一个2×M整型二维数组中最大元素的值,并将此值返回调用函数。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fan的花括号中填入所编写的若干语句。
试题程序:
define M 4
include <stdio.h>
fun(int a[] [M])
{
}
main()
{
int arr[2][M]={5, 8, 3, 45, 76, -4, 12, 82};
printf("max=%d\n",fun(arr));
}
请编写一个函数fun(),它的功能是:求出一个4×M整型二维数组中最小元素的值,并将此值返回调用函数。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仪在函数fun的花括号中填入所编写的若干语句。
试题程序:
define M 4
include<stdio.h>
fun (int a[])[M])
{
}
main()
{
int arr[4][M]={11,3,9,35,42,-4,24,32,6,48,-32,7,23,34,12,-7);
printf(“min=%d\n”,fun(arr));
}
请编写函数fun,其功能是求出数组的最大元素在数组中的下标并存放在k所指的存储单元中。
例如,输入如下整数:876 675 896 10l 30l 401 980 431451 777则输出结果为:6,980
注意:部分源程序在文件PROGl.C文件中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
请编写函数fun(),它的功能是计算下列级数和,和值由函数值返回。
S=1-x+x2(上标)/2!-x3(上标)/3!+…+ (-1*x) n(上标)/n!
例如,当n=15,x=0.5时,函数值为0.606531。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<conio.h>
include<stdio.h>
include<math.h>
double fun(double x, int n)
{
}
main()
{
clrscr();
printf("%f ",fun (0.5,15));
}
为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!