更多"下列给定程序中,函数fun( )的功能是计算并输出high以内的素数之"的相关试题:
[简答题]下列给定程序中,函数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));
[简答题]改错题
下列给定程序中,函数fun( )的功能是计算并输出high以内的素数之和。high由主函数传给fun( )函数。若high的值为100,则函数的值为1060。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
#include
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));
}
[简答题]下列给定程序中,函数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));
[填空题]给定程序MODI1.C中函数fun的功能是:计算并输出high以内最大的10个素数之和。high的值由主函数传给fun函数。若high的值为100,则函数的值为732。
请改正程序中的错误,使程序能输出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
文件MODI1.C内容如下:
#include<stdio.h>
#include<math.h>
int fun(int high)
int sum=0,n=0,j,yes;
/**********found**********/
while((high>=2)&&(n<10))
yes=1;
for(j=2;j<=high/2;j++)
if(high%j==0)
/**********found**********/
yes=0;break
if(yes)
sum+=high:
n++;
high--;
return sum;
void main( )
printf("%d/n",fun(100));
[填空题]下列给定程序中函数fun( )的功能是:计算n!。例如,给 n输入5,则输出120.000000。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio.h>
#include <conio.h>
double fun (int n)
double result=l.0;
/*************found**************/
if n==0
return 1.0;
while (n>l&&n<170)
/*************found**************/
result *=n--
return result;
main ( )
int n;
printf ("Input N: ");
scanf ( "%d" &n);
printf ("/n/n%d!=%lf/n/n",n, fun(n));
[填空题]下列给定程序中函数fun( )的功能是计算1/n!的值。
例如:给n输入5,则输出0.0083330
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio.h>
#include <conio.h>
/******+****found*************/
int fun(int n)
{ double result=1.0;
if(n==0)
return 1.0;
while(n>1 && n<170)
/**********found************/
result *=n++;
result=1/result;
return result;
}
main( )
{
int n;
printf("Input N:");
scanf("%d",&n);
printf("/n1/%d!=%If/n",n,fun(n));
}
[填空题]下列给定程序中函数fun( )的功能是计算1/n!的值。
例如:给n输入5,则输出0.0083330
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio.h>
#include <conio.h>
/******+****found*************/
int fun(int n)
double result=1.0;
if(n==0)
return 1.0;
while(n>1 && n<170)
/**********found************/
result *=n++;
result=1/result;
return result;
main( )
int n;
printf("Input N:");
scanf("%d",&n);
printf("/n1/%d!=%If/n",n,fun(n));
[填空题]下列给定程序中,函数fun( )的功能是:给定n个实数,输出平均值,并统计平均值以上(含平均值)的实数个数。例如, n=8时,输入193.199,195.673,195.757,196.051,196.092, 196.596,196.579,196.763,所得平均值为195.838745,在平均值以上的实数个数应为5。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <conio.h>
#include <stdio.h>
int fun(float x[], int n)
/***************found*******************/
iht j, c=0;float xa=0.0;
for (j=0; j<n;.j++)
xa+=x[j]/n;
printf("ave=%f/n",xa);
for (j=0; j<n;j++)
if(x[j]>=xa)
c++;
returnc;
main( )
float x[l00]= 193.199,195.673,195.757,
196.051,196.092,196.596,
196.579,196.763;
clrscr ( );
printf("%d/n",fun (x,8));
[填空题]下列给定程序中,函数 fun( ) 的功能是:计算并输出下列级数的的N项之和SN,直到SN+1大于q为止,q的值通过形参传入。
SN=2/1+3/2+4/3+(N+1)/N
例如,若q的值为50.0,则函数值为49.394948。
请改正程序中的错误,使它能得出正确的结果。
注意;不要改动main 函数,不得增行或删行,也不得更改程序的结构.
试题程序:
#include <conio.h>
#include <stdio. h>
/**************found***************/
double fun(double q)
{ int n; double s,t;
n=2;
s=2.0;
while (s<=q)
{
t=s
/*************found *************/
s=s+ (n+1)/n;
n++;
}
printf ("n=%d/n ", n);
/************found***************/
return s;
}
main ( )
{ clrscr( );
printf ("%f/n ",fun (50));
}
[简答题]给定程序MODI1.C中函数 fun 的功能是:计算n!。
例如,给n输入5,则输出120.000000。
请改正程序中的错误,使程序能输出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
double fun ( int n )
{ double result = 1.0 ;
if n = = 0
return 1.0 ;
while( n >1 && n < 170 )
result *= n--
return result ;
}
main ( )
{ int n ;
printf("Input N:") ;
scanf("%d", &n) ;
printf("/n/n%d! =%lf/n/n", n, fun(n)) ;
}
[填空题]由N个有序整数组成的数列已放在一维数组中,下列给定程序函数fun的功能是:利用折半查找法查找整数m在数组中的位置。若找到,返回其下标值;否则,返回-1。
折半查找的基本算法是:每次查找前先确定数组中待查的范围low和high(low<high),然后用m与中间位置(mid)上元素的值进行比较。如果m的值大于中间位置元素的值,则下一次的查找范围落在中间位置之后的元素中;反之,下一次的查找范围落在中间位置之前的元素中,直到low>high,查找结束。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#define N 10
/**********found**********/
void fun(int a[],int m)
int low=0,high=N-1,mid;
while(low<=high)
mid=(low+high)/2;
if(m<a[mid])
high=mid-1;
/********found**********/
else if(m>a[mid])
low=mid+1;
else return(mid);
return(-1);
void main( )
int i,a[N]=(-3,4,7,9,13,45,67,89,100,180),
k,m;
printf("a数组中的数据如下:");
for(i=0;i<N;i++)
printf("%d",a[i]);
printf("Enter m:");
scanf("%d",&m);
k=fun(a,m);
if(k>=0)
printf("m=%d,index=%d/n",m,k);
else printf("Not be found /n");
[简答题]给定程序中,函数fun的功能是根据形参i的值返回某个函数的值。当调用正确时, 程序输出: x1=5.000000, x2=3.000000, x1*x1+x1*x2=40.000000 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构! 给定源程序: #include double f1(double x) { return x*x; } double f2(double x, double y) { return x*y; } __1__ fun(int i, double x, double y) { if (i==1) return __2__(x); else return __3__(x, y); } main( ) { double x1=5, x2=3, r; r = fun(1, x1, x2); r += fun(2, x1, x2); printf("/nx1=%f, x2=%f, x1*x1+x1*x2=%f/n/n",x1, x2, r); }
[简答题]给定一个函数,其函数功能为:使10个整数按由小到大的顺序排列。在主函数中输入10个数,并输出结果。使用VC6打开考生文件夹下的工程RevProj5。此工程包含一个源程序文件RevMain5.cpp,该程序实现上述功能。但此程序运行有问题。请找出错误的地方,改正后将此程序调试正确。
注意:不得删行或增行,也不得更改程序结构。
文件RevMain5.cpp中的程序清单如下:
//RevMain5.cpp
#include<iostream>
#include<iomanip>
using namespace std;
int main( )
void sort(int array[],int n);
int data[10],*p,i;
cout<<"Input 10 numbers/n";
for (i=0; i<10; i++)
cin>>data [i];
cout<<"the origined array is:";
for (p=data;p<data+10;p++)
if((p-&data[0]) %5==0)
cout<<" /n";
cout<<setw (5) <<*p;
sort (data, 10);
cout<<"/n the present array is:";
for(p=data;p〈data+10;p++)
if((p-&data[0])%5==0) cout<<"/n";
cout<<setw (5)<<*p;
void sort(int array[],int n)
/* * * * * * * * *found * * * * * * * * * */
for(p1=array;p1<array+(n-1) ;p1++)
for (p2=p1+1 ;p2<array+n;p
[填空题]下列给定程序中函数fun( )的功能是计算正整数num的各位上的数字之平方和。
例如:输入352,则输出应该是38;若输入328,则输出应该是77。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio.h>
#include <conio.h>
long fun(long num)
/*+**+*+*+*found************/
long k=1;
do
k+=(num%10)*(num%10);
num/=10;
/*********+found*+**+*+******/
while(num)
return(k);
main( )
long n;
clrscr( );
printf("/Please enter a number:");
scanf("%ld",&n);
printf("/n%ld/n",fun(n));