更多"下列给定程序中,函数fun( )的功能是:从3个红球,5个白球,6个黑"的相关试题:
[填空题]下列给定程序中,函数fun( )的功能是:找出一个大于给定整数m且紧随m的素数,并作为函数值返回。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构.
试题程序:
#include <conio.h>
#include <stdio.h>
int fun( int m)
{ int i,k;
for (i=m+1; ;i++)
{ for (k=2;k<i;k++)
/*************found**************/
if (i%k!=0)
break;
/*************found**************/
if (k<i)
return(i);
}
}
main( )
{ int n;
clrscr ( );
printf("/nPlease enter n: ");
scanf ("%d", &n);
printf ("%d/n",fun(n));
}
[简答题]下列给定程序中,函数fun的功能是:求两个非零正整数的最大公约数,并作为函数值返回。
请改正程序中的错误,使它能得出正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
int fun(int a, int b)
int r, t;
if(a<b)
t=a; b=a; a=t;
/******************found*******************/
r=a%b;
while(r!=0)
a=b; b=r; r=a%b;
/******************found*******************/
return(a);
void main( )
int num1, num2, a;
printf("Input num1 num2:");
scanf("%d%d", &num1, &num2);
printf("num1=%d num2=%d/n/n", num1, num2);
a=fun(num1, num2);
printf("The maximun common divisor is%d/n/n",a);
[简答题]下列给定程序中,函数fun的功能是:计算正整数num各位上的数字之积。
注意:不要改动maln函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include <stdio.h >
#include <conio.h>
long fun (long num)
/********** found********** /
long k;
do
k*=num% 10;
/********** found********** /
num/=10;
while (num);
return (k);
main ( )
long n;
printf ("/ n please enter a num-
ber: ");
scanf("% 1d", &n);
printf("/n% 1d/n", fun(n));
[简答题]改错题
下列给定程序中,函数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));
[简答题]下列给定程序中,函数fun的功能是:计算并输出high以内最大的10个素数的和。high的值由主函数传给fun函数。
例如,若high的值为10。,则函数的值为732。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<conio.h>
#include<scdio.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;
main( )
printf("%d/n",fun(100));
[简答题]给定程序中,函数fun的功能是将参数给定的字符串、整数、浮点数写到文本文件中,再用字符串方式从此文本文件中逐个读入,并调用库函数atoi和atof将字符串转换成相应的整数、浮点数,然后将其显示在屏幕上。
请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#include
void fun(char *s, int a, double f)
{
/**********found**********/
__1__ fp;
char str[100], str1[100], str2[100];
int a1; double f1;
fp = fopen("file1.txt", "w");
fprintf(fp, "%s %d %f/n", s, a, f);
/**********found**********/
__2__ ;
fp = fopen("file1.txt", "r");
/**********found**********/
fscanf(__3__,"%s%s%s", str, str1, str2);
fclose(fp);
a1 = atoi(str1);
f1 = atof(str2);
printf("/nThe result :/n/n%s %d %f/n", str, a1, f1);
}
main( )
{ char a[10]="Hello!"; int b=12345;
double c= 98.76;
fun(a,b,c);
}
[填空题]下列给定程序中,函数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( )的功能是将形参给定的字符串、整数、浮点数写到文本文件中,再用字符方式从该文本文件中逐个读入并显示在终端屏幕上。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
#include <stdio.h>
void fun(char *s,int a,double f)
/**********found**********/
(1) fp;
char ch;
fp=fopen("file1.txt","w");
fprintf(fp,"%s%d%f/n",s,a,f);
fclose(fp);
fp=fopen("file1.txt","r");
printf("/nThe result:/n/n");
ch=fgetc(fp);
/**********found**********/
while(!feof( (2) ))
/**********found**********/
putchar( (3) );ch=fgetc(fp);)
putchar(’/n’);
fclose(fp);
main( )
char a[10]="Hello!";int b=12345;
double c=98.76;
fun(a,b,c);
[简答题]改错题
下列给定程序中,函数fun( )的功能是:读入一个字符串(长度<20),将该字符串中的所有字符按ASCII码降序排序后输出。
例如:输入dafhc,则应输出hfdca。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
/**********************found***********************/
int fun(char t[ ])
{
char c;
int i,j;
for(i=0;i
[简答题]下列给定程序中,函数fun的功能是:求两个非零正整数的最大公约数,并作为函数值返回。
例如,若num1和num2分别为49和21,则输出的最大公约数为7;若num1和num2分别为27和81,则输出的最大公约数为27。
请改正程序中的错误,使它能得出正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
intfun(int a,int b)
int r,t;
if(a<b)
/**********found***********/
t=a;b=a;a=t;
r=a%b;
while(r!=0)
a=b;b=r;r=a%b;
/*************found**********/
return(a);
void main( )
int num1,num2,a;
printf("Input num1 num2:");
scanf("%d%d",&num1,&num2);
printf("num1=%d num2=%&n/n",num1,num2);
a=fun(num1,num2);
printf("The maximun common divisor is%d/n/n",a);
[填空题]下列给定程序中函数fun的功能是:把从主函数中输入的3个数,最大的数放在a中,中间的数放在b中,最小的数放在C中。
例如,若输入的数为:55 12 34,输出的结果应当是.a=55.0,b=34.0,c=12.0。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
void fun(float*a,float*b,float*c)
/*********found*********/
float*k;
if(*a<*b)
k=*a:
*a=*b:
*b=k;
/*********found*********/
if(*a>*c)
k=*c:
*c=*a:
*a=k;
if(*b<*c)
k=*b;
*b=*c;
*c=k;
void main( )
float a,b,c;
printf("Input a b c:");
scanf("%f%f%f",&a,&b,&c);
printf("a=%4.1f,b=%4.1f,c=%4.1f/n/n",a,b,c);
fun(&a,&b,&c);
printf("a=%4.1f,b=%4.1f,c=%4.1f/n/n",a,b,c);
[简答题]下列给定程序中,函数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));