![](https://lstatic.shangxueba.com/jiandati/h5/images/m_q_title.png)
试题29有以下函数int fun(char *x, char *y){ int n=0;while ((*x==*y)&&*x!=’\0’) {x++; y++; n++;}return n;}函数的功能是()
A.查找x和y所指字符串中是否有’\n’
B.统计x和y所指字符串中最前面连续相同的字符个数
C.将y所指字符串赋给x所指存储空间
D.统计x和y所指字符串中相同的字符个数
A.查找x和y所指字符串中是否有’\n’
B.统计x和y所指字符串中最前面连续相同的字符个数
C.将y所指字符串赋给x所指存储空间
D.统计x和y所指字符串中相同的字符个数
试题14
以下程序调用fun函数把x中的值插入到a数组下标为k的数组元素中。主函数中,n存放a数组中数据的个数。请填空。
#include <stdio.h>
void fun(int s[], int *n, int k, int x)
{ int i;
for(i=*n-1; i>=k; i- - ) s[ ___ ]=s[i];
s[k]=x;
*n=*n+______;
}
main()
{ int a[20]={1,2,3,4,5,6,7,8,9,10,11}, i, x=0, k=6, n=11;
fun(a, &n, k, x);
for(i=0; i<n; i++) printf(“%4d”,a[i]); printf(“\n”);
}
函数fun的功能是:求出以下分数序列的前n项之和,和值通过函数值返回。例如,n=10,则输出16.479905。#include <stdio.h> double fun(int n) { int a,b,c,k; double s; [29] ; a=2; b=1; for (k=1; k<=n;k++) { s="s+(double)a/b;" c="a;" ; b="c;" } return s; void main() int n="10;" printf("\nthe value of function is: %lf\n",fun(n));>
函数fun的功能是:求出以下分数序列的前n项之和,和值通过函数值返回。例如,n=10,则输出16.479905。#include <stdio.h> double fun(int n) { int a,b,c,k; double s; [29] ; a=2; b=1; for (k=1; k<=n;k++) { s="s+(double)a/b;" c="a;" ; b="c;" } return s; void main() int n="10;" printf("\nthe value of function is: %lf\n",fun(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);
}
下列给定的程序中,函数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(),它的功能是;根据以下公式求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()的功能是:求出以下分数序列的前n项之和。
2/1,3/2,5/3,8/5,13/8,21/13,……
和值通过函数值返回main()函数。例如,若输入n=5,则应输出8.391667。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio.h>
include <stdio.h>
/*************found**************/
fun (int n)
{ int a=2,b=l,c, k;
double s=0.0;
for(k=l;k<=n;k++)
{s=s+l.0*a/b;
/*************found**************/
c=a; a+=b; b+=c;
}
return (s);
}
main ()
{ int n=5;
clrscr ();
printf("\nThe value of function is:
%1f\n", fun (n));
}
有以下程序
#include
void fun(int *p)
{ printf(“%d\n”,p[5]);}
main()
{ int a[10]={1,2,3,4,5,6,7,8,9,10};
fun(&a[3]);
}
程序运行后的输出结果是()
A.5
B.6
C.8
D.9
例如,若x中的值为30,则有4个数符合要求,它们是1,3,5,15。
请按题意,完成填空。
试题程序:
#include <conio.h>
#include <stdio.h>
void fun (int x, int pp[], int *n)
{ int i,j=0;
【13】
if(x%i==0)pp[j++]=i;
【14】;
}
main ()
{ int? x,aa[1000], n, i ;
clrscr();
printf("\nPlease enter an integer number : \n "); scanf ("%d ", &x);
fun (x, aa, &n);
for (i=0 ; i<n ; i++)
printf ("%d ", aa [i]);
printf ("\n ");
}
请编写函数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);
}
为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!