给定的程序中,fun函数的功能是:将M行N列的矩阵中的数据,按行的顺序依次放在一维数组中,一维数组
第1题
下列给定程序中,函数fun()的功能是计算并输出high以内的素数之和。high由主函数传给fun()函数。
例如:若high的值为100,则函数的返回值为1060。
请改正程序中的错误,使它能得到正确结果。
[注意] 不要改动main函数,不得增行或删行,也不得更改程序的结构。
[试题源程序]
include <conio.h>
include <stdio.h>
include<math.h>
int fun(int high)
{
int sum=0, n=0, j, yes;
while(high>=2)
{
yes=1;
for(j=2;j<=high/2; j++)
**********************found**********************/
ifhigh%j==0
{
yes=0;
break;
}
/**********************found**********************/
if(yes==0)
{
sum+=high;
n++;
}
high--;
}
return sum;
}
main()
{
clrscr();
printf("%d\n", fun(100));
}
第2题
请编写函数fun(),该函数的功能是:将M行N列的二维数组中的字符数据,按列的顺序依次放到一个字符串中。
例如,若二维数组中的数据为:
W WWW
S S S S
H H H H
则字符串中的内容应是WSHWSHWSHWSH。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<stdio.h>
define M 3
define N 4
void fun(char (*s)[N],char *b)
{
}
main()
{
char a[100],w[M][N]={{ 'W', 'W', 'W', 'W'},
{'S', 'S', 'S', 'S'},{'H', 'H', 'H', 'H'}};
int i,j;
printf("The matrix:\n");
for(i=0;i<M;i++)
{ for(j=0;j<N;j++)
printf("%3c",w[i][j]);
printf("\n");
}
fun(w,a);
printf("The A string:In");
puts(a);
printf("\n\n");
}
第3题
例如,形参s所指的字符串为:Abe@1x56*。程序执行后t所指字符数组中的字符串应为:A@156*。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANKl.C中。
不得增行或删行,也不得更改程序的结构!
第4题
在给定程序中,函数fun的功能是:根据以下公式求π值,并作为函数值返回。
例如,给指定精度的变量eps输入0.0005时,应当输出Pi=3.140578。 请改正程序中的错误,使它能得出正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 include include include double fun(double eps) {double s,t; int n=1; s=0.0; /************found************/ t=0; while(t>eps) {s+=t; t=t*n/(2*n+1); n++; } /************found************/ return(S); } main() {double x; printf("\nPlease enter a preciSion:")j scanf(”%1f”,&x); printf("\neps=%1f,Pi=%1f\n\n",x,fun(x)); )
第5题
给定程序MODI1.C中函数fun的功能是:读入整数k(2≤k≤10000),打印它的所有质因子(即所有素数的因子),例如,若输入整数2310,则应输出:2,3,5,7,11。 include"conio.h" include”stdio.h” /************found************/ IsPrime(int n); { int i,m; m=1; for(i=2;i<n;i++) /************found************/ if !(n%i) {m=0;break;} return (m); } main() { int j,k; clrscr(); printf("\nPlease input a unmber between 2 and 10000:"); scanf("%d",&k); printf("\n The prime factor (s) are:\n"); for(j=2;j<=k;j++) if((!k%j))&&(IsPrime(j))) printf("\n%4d",j); printf("\n"); }
第6题
给定程序中,函数fun的功能是:计算形参x所指数组中N个数的平均值(规定所有数均为正数),作为函数值返回;并将大于平均值的数放在形参y所指数组中,在主函数中输出。
例如,有10个正数:46 30 32 40 6 17 45 1548 26,平均值为:30.500000主函数中输出:46 32 40 45 48
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANKl.C中。
不得增行或删行,也不得更改程序的结构!
第7题
请改正程序中的错误,使它能得出正确的结果。
注意:部分源程序在文件MODll.C中,不得增行或删行,也不得更改程序的结构!
第8题
下列给定程序中,函数fun()的功能是:根据输入的3个边长(整型值),判断能否构成三角形:若能构成等边三角形,则返回3,若是等腰三角形,则返回2,若能构成三角形则返回1,若不能,则返回0。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <math. h>
int fun(int a, int b, int c)
{ if (a+b>c&&b+c>a&&a+c>b)
{ if (a==b&&b==c)
/*************found**************/
return 1;
else if(a==b|| b==c||a==c)
return 2;
/*************found**************/
else return 3;
}
else return 0;
}
main ()
{ int a,b, c, shape;
printf("\nInput a,b,c: ");
scanf ("%d%d%d", &a, &b, &c);
printf ("\na=%d, b=%d, c=%d\n",a,b,c);
shape=fun (a,b, c);
printf ("\n\nThe shape : %d\n", shape);
}
第9题
下列给定的程序中,函数hn()的功能是:为一个偶数寻找两个素数,这两个素数之和等于该偶数,并将这两个素数通过形参指针传回主函数。
请改正函数fun()中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
include <math.h>
void fun(int a, int *b, int *c)
{ int i,j,d,y;
for (i=3;i<=a/2;i=i+2)
/*************found**************/
{y=0;
for (j=2;j<=sqrt((double)i);j++)
if (i%j==0) y=0;
if (y==1)
/*************found**************/
{ d=i-a;
for (j-2;j<=sqrt((double)d);
j++)
if (d%j==0) y=0;
if (y=-1)
{*b=i; *c=d;}
}
}
}
main ()
{ int a,b,c;
do
{ printf("\nInput a: ");
scanf ("%d", &a); }
while (a%2);
fun (a, &b, &c);
printf ("\n\n%d=%d+%d\n", a,b,c);
}
第10题
给定程序MODI1.C中函数fun的功能是:求出以下分数序列的前n项之和。
和值通过函数值返回main函数。例如,n=10,则输出16.479905。 /************found************/ fun(int n) { int a,b,c,k;double s; s=0.0;a=2;b=1; for (k=1;k<=n;k++) {/***********found************/ s=s+(Double)a/b; } } main() { int n=10; clrscr(); printf("\n The value of function is:%lf\n",fun(n)); }