国外流行FUN的家庭生活方式,其内容包括()
第1题:
请编写一个函数int fun(int n),其中n为自然数。函数fun()的功能是求出自然数n(包括n)以内所有素数的和,并返回其值。
注意;部分源程序已存在文件PROC11.cpp中。
请勿修改主函数和其他函数中的任何内容,仅在函数fun()的花括号中填写若干语句。
文件PROC11.cpp的内容如下:
//PROC11.cpp
include<iostream>
using namespace std;
int fun(int n);
int main()
{
int number;
cout<<"Enter the number which you want to caculate: \n";
cin>>number;
cout<<"The result is:"<<fun(number)<<end1;
return 0;
}
int fun(int n)
{
//* * * * * * * * *
}
第2题:
请编写函数fun(),其功能是;计算井输出下列多项式值。
S=(1-1/2)+(1/3-1/4)+…+(1/(2n-1)-1/2n)
例如,若主函数从键盘给n输入8后,则输出为 S-0.662872。
注意;部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仅在函数fun 的花括号中填入所编写的若干语句。
试题程序;
include<stdio. h>
double fun(int n)
{
}
main ()
{
int n;
double s;
printf("\nInput n: ");
scanf ("%d", &n);
s=fun (n);
printf ("\ns=%f\n ", s);
}
第3题:
数组xx[N]保存着一组4位无符号整数,其元素的个数通过变量num传入函数fun()。请补充函数fun(),该函数的功能是:从数组xx中找出个位和百位的数字相等的所有无符号整数,结果保存在数组yy中,其个数由函数fun()返回。
例如:当xx[8]={1111,2413,2321,2222,4245,3333,1414, 5335}时,bb[6]={1111,2321,2222,4245,3333,1414)。
注意:部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio. h>
include<conio. h>
define N 1000
int fun (int xx [], int bb [], int num)
{
int i, n=0;
int g,b;
for (i=0; i<num; i++)
{
g=【 】;
b=xx [i]/100%10;
if (g==b)
【 】
}
return【 】;
}
main()
{
int xx [8] ={1111,2413, 2321, 2222, 4245,
3333,1414,5335 };
int yy[N];
int num=0, n=0, i=0;
num=8;
clrscr ();
printf ("*****original data ******\n ");
for (i=0; i<num; i++)
printf ("%u ",xx[i]);
printf ("\n\n\n");
n=fun (xx, yy, num);
printf ("\n yy= ");
for (i=0; i<n; i++)
printf ("%u ", yy [i]);
}
第4题:
请编写一个函数void fun(int p[],int n,int c),其中数组p的元素按由小到大的顺序排列,其元素个数为n。函数fun()的功能是将c插入到数组p中,且保持数组的升序排列。
注意:部分源程序已存在文件PROC9.cpp中。
请勿修改主函数和其他函数中的任何内容,仅在函数fun()的花括号中填写若干语句;
文件PROC9.cpp的内容如下:
//PROC9.cpp
include <iostream>
include <string>
using namespace std;
define M 30
void fun(int p[ ],int n,int c);
int main ()
{
int pp[M],n,i;
int fg, c;
cout<<"Please input n:\n";
cin>>n;
cout<<"Please input the n data:\n";
for (i=0; i<n; i++)
cin>>pp [i];
cout<<"Please input c:\n";
cin>>c;
fun (pp, n, c);
for (i=0; i<n; i++)
cout<<pp [i] << " " ;
cout<<end1;
return 0;
}
void fun(int p[ ],int n, int c)
{
//* * * * * * * * *
}
第5题:
请编写函数fun(),其功能是:计算并输出下列多项式的值。
S=1+4/(1+2)+1/(1+2+3)+…+1/(1+2+3+…+n)
例如,着主函数从键盘给n输入50后,则输出为 S=1.960784。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
double fun(int n)
{
}
main ()
{
int n;
double s;
printf ("\nInput n: ");
scanf ("%d", &n);
s=fun (n);
printf ("\n\ns=%f\n\n", s);
}
第6题:
请编写函数fun(),它的功能是求Fibonacci数列中小于t的最大的一个数,结果由函数返回。其中Fibonacci数列F(n)的定义为
F(0)=0,F(1)=1
F(n)=F(n-1)+F(n-2)
例如:t=1000时,函数值为987。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <math.h>
include <stdio.h>
int fun(int t)
{
}
main()
{
int n;
clrscr();
n=1000;
printf("n=%d, f=%d\n",n, fun(n));
}
第7题:
以下程序的输出结果是( )。 #include<stdio.h> int fun(int n,int *s) { int f1,f2; if(n==0||n==1) *s=1; else { fun(n-1,&f1); fun(n-2,&f2); *s=f1+f2; } } void main() { int x; fun(6,&x); printf("\n%d" ,x);}
A.7
B.13
C.9
D.10
第8题:
请编写函数fun(),它的功能是计算:s=(1-In(1)-In(2)-In(3)-…-1n(m))2
s作为函数值返回。
在C语言中可调用log(n)函数求In(n)。log函数的引用说明是double log(double x)。
例如,若m的值为15,则fun()函数值为723.570801。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <conio.h>
include <stdio.h>
include <math.h>
double fun(int m)
{
}
main()
{
clrscr();
printf("%f\n",fun(15));
}
第9题:
请编写函数fun(),其功能是:计算并输出下列多项式值。
S=(1+1/2)+(1/3+1/4)+…+(1/(2n-1)+l/2n)
例如,若主函数从键盘给n输入12后,则输出为 S=3.775958。
n的值要求大于1但不大于100。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<stdio.h>
double fun(int n)
{
}
main()
{
int n;
double s;
printf("\nlnput n:");
scanf("%d",&n);
s=fun(n);
printf("\ns=%f\n",s);
}
第10题:
请编写函数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);
}
第11题:
发电机的空载特性是指()的函数关系。
第12题:
第13题:
请补充函数fun(),函数fun()的功能是求7的阶乘。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
long fun(int n)
{
if(【 】)
return(n*fun(【 】);
else if(【 】)
return 1;
}
main()
{
int k=7;
printf("%d!=%ld\n", k, fun(k));
}
第14题:
有以下程序
#include<stdi0.h>
void fun(int n,int*p)
( int f1,f2;
if(n==1|| n==2)*p=1;
else
{ fun(n-1,&f1);fun(n-2,&f2);
*p=f1+f2;
}
}
main
{ int s;
fun(3,&s);printf("%d",s);
}
程序的运行结果是( )。
A.2
B.3
C.4
D.5
第15题:
请完成函数fun( ),它的功能是:求Fibonacc数列中小于t的最大的一个数,结果由函数 0返回。Fibonacc数列F(n)定义为:
F(0)=0,F(1)=1
F(n)=F(n-1)+F(n-2)
例如:t=1000时,函数为987。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在下划线上填入所需的内容。
include<conio.h>
include<stdio.h>
include<math.h>
in fun(int t)
{
int a=l,b=1,c=0,i;
do
{
【 】;
a=b;
b=C;
}
while( 【 】);
c= 【 】;
return C;
}
main()
{
int n;
clrscr();
n=1000;
printf("n=%d,f=%d\n",n,fun(n));
}
第16题:
编写函数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));
}
第17题:
编写函数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);
}
第18题:
有以下程序 #include <stdio.h> void fun(int n, int *p) { int f1,t2; if(n==1 ||n==2) *p=1; else { fun(n-1,&f1); fun(n-2,&f2); *p=f1+f2; } } main() { int s; fun(3,&s); printf("%d\n", s ); }
A.2
B.3
C.4
D.5
第19题:
请编写函数fun(),其功能是:计算并输出给定10个数的方差。
其中
例如,给定的10个数为95.0,89.0,76.0,65.0,88.0, 72.0,85.0,81.0,90.0,56.0,则输出为S=11.730729。
注意;部分源程序给出如下.
请勿改动主函数mam和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<math.h>
include<stdio.h>
double fun(double x[10])
{
}
main()
{
double s,x[i0]={95.0,89.0,76.0,65.0,
88.0,72.0,85.0,81.0,90.0,56.0};
int i;
printf("\nThe original data is:\n");
for(i=0;i<10;i++)
printf("%6.1f ",x[i]);
printf("\n\n ");
s=fun(x);
printf("s=%f\n\n ",s);
}
第20题:
请编写一个函数unsigned fun (unsigned w),w 是一个大于 10的无符号整数,若w是n(n≥2)位的整数,则函数求出w的后 n-1位的数作为函数值返回。
例如:w值为5923,则函数返回923;若w值为923,则函数返回23。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun 的花括号中填入所编写的若干语句。
试题程序:
include<conio. h>
include<stdio. h>
unsigned fun(unsigned w)
{
}
main()
{
unsigned x;
clrscr ();
printf("Enter a unsigned integer
number: ");
scanf ("%u",&x);
printf("The original data is:%u\n",x);
if (x<10)
printf ("Data error! ");
else
printf ("The result :%u\n", fun(x) );
}
第21题:
有以下程序: #include<stdio.h> iht fun(iht n,int*p) { int f1,f2; if(n==1||,n==2)*p=1; else { fun(n-1,&f1);fun(n-2,&f2); *p=f1+f2; } } main() { int s; fun(3,&s); printf("%d\n",s); } 程序的运行结果是______。
A.2
B.3
C.4
D.5
第22题:
有以下程序
#include<stdio.h>
void fun(int n,int *p)
{
int f1,f2;
if(n==1||n==2) *p=1;
else
{
fun(n-1,&f1); fun(n-2,&f2);
p=f1+f2;
}
}
main()
{
int s;
fun(3,&s); printf(“%d\n”,s);
}
程序运行的结果为( )。
A.2
B.3
C.4
D.5
第23题:
F—健身
U—和谐
N—营养
其他