更多"请补充fun函数,fun函数的功能是求n的阶乘。 注意:部分源程序已"的相关试题:
[填空题]请补充fun函数,fun函数的功能是求n的阶乘。
注意:部分源程序已给出。
请勿改动主函数main和其他函数中的任何内容,仅在fun函数的横线上填入所编写的若干表达式或语句
试题程序:
#include<stdio.h>
long fun(int n)
if( (1) )
return(n*fun( (2) ));
return (3) ;
main( )
printf("10!=%1d/n",fun(10));
[填空题]请补充fun( )函数,该函数的功能是求m的阶乘。不要改动主函数main( )与他函数中的任何内容,仅在fun( )函数的横线上填写所需的若干表达式或语句。
注意:部分源程序如下。
#include<stdio.h>
long fun(int m)
if (1)
return(m*fun (2) );
return (3) ;
main( )
printf("8!=%ld/n",fun(8));
[填空题]请补充函数proc( ),函数proc( )的功能是求7的阶乘。
注意:部分源程序已给出。
请勿改动主函数main和其他函数中的任何内容。
试题程序:
#include<stdio.h>
long proc(int n)
if( (1) )
return(n * proc( (2) );
else if( (3) )
return 1;
void main( )
int k=7;
printf("%d!=%ld/n", k, proc(k));
[填空题]下列给定程序中,函数fun( )的功能是:根据以下公式求n的值,并作为函数值返回。例如,给指定精度的变量eps输入 0.0005时,应当输出Pi=3.140578。
n/2=1+1/3+1/3*2/5+1/3*2/5*3/7+1/3*2/5*3/7*4/9……
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <conio.h>
#include <stdio.h>
#include <math.h>
double fun(double eps)
double s,t; int n=t;
s=0.0;
/*************found**************/
t=1;
/*************found**************/
while(t>eps)
s+=t;
t=t*n/(2*n+1);
n++;
/*************found**************/
return (s);
main( )
double x;
printf("/nPlease enter a precision: ");
scanf("%1f",&x);
printf("/nPi=%1f/n ",fun(x));
[简答题]编写函数fun( ),它的功能是求n以内(不包括n)同时能被5与11整除的所有自然数之和的平方根s,并作为函数值返回。
例如:n为1000时,函数值应为s=96.979379。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <conio.h>
#include <math.h>
#include <stdio.h>
double fun(int n)
main( )
clrscr( );
printf("s=%f/n",fun(1000));
[简答题]编写函数fun( ),它的功能是求n以内(不包括n)同时能被3与7整除的所有自然数之和的平方根s,并做为函数值返回。例如:n为1000时,函数值应为s=153.909064。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <conio.h>
#include <math.h>
#include <stdio.h>
double fun(int n)
main( )
clrscr( );
printf("s=%f/n", fun(1000));
[填空题]下列程序中,fun( )函数的功能是计算x2-2x+6,主函数中将调用fun( )函数计算。
y1=(x+8)2-2(x+8)+6
y2=sin2(x)-2sin(x)+6
请填空
#include "math.h"
double fun(double x)return(x*x-2*x+6);)
main( )
double x,y1,y2;
printf("enter x:");scanf("%1f",&x);
y1=fun(______);
y2=fun(______);
printf("y1=%1f,y2=%1f/n",y1,y2);
[填空题]下列程序中,fun( )函数的功能是计算x2-2x+6,主函数中将调用fun( )函数计算。
y1=(x+8)2=2(x+8)+6
y2=sin2(x)-2sin(x)+6
请填空:
#include<math.h>
double fun(double x)return(x*x-2*x+6);
main( )
double x, y1, y2;
printf("enter x: "); scanf("%1f", &x);
y1=fun(______);
y2=fun(______);
printf("y1=%1f, y2=%1f/n", y1, y2);
[简答题]请编写函数fun( ),函数的功能是求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。
例如:若二维数组中的值为
1 3 5 7 9
2 9 9 9 4
6 9 9 9 8
1 3 5 7 0
则函数值为61。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include<conio.h>
#include<stdio.h>
#define M 4
#define N 5
int fun( int a [M][N])
{
}
main( )
{
int aa[M][N]={{1,3,5,7,9},{2,9,9,9,4},
{6,9,9,9,8},{1,3,5,7,0}};
int i, j, y;
clrscr( );
printf ("The original data is :/n ");
for(i=0; i<N;i++)
{for (j=0; j<N;j++)
printf("%6d ",aa[i][j]);
printf("/n ");
}
y=fun(aa);
printf("/nThe sun:%d/n ",y);
printf("/n");
}
[简答题]编写函数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);