更多"下列给定程序中,函数fun( )的功能是:通过某种方式实现两个变量值的"的相关试题:
[填空题]下列给定程序中,函数proc( )的功能是:通过某种方式实现两个变量值的交换,规定不允许增加语句和表达式。例如变量num1中的值原为2,num2中的值原为1,程序运行后num1中的值为1,num2中的值为2。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main( )函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
int proc(int*x,int y)
{
int t;
//****found****
t=x;
*x=y;
//****found****
return(y);
}
void main( )
{
int num1=2,num2=1;
system("CLS");
printf("%d%d/n",num1,num2);
num2=proc(&num1,num2);
printf("%d%d/n",num1,num2);
}
[填空题]下列给定程序中,函数fun( )的功能是:通过某种方式实现两个变量值的交换,规定不允许增加语句和表达式。例如变量a中的值原为8,b中的值原为3,程序运行后a中的值为3, b中的值为8。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<conio.h>
#include <stdio.h>
int fun(int *x,int y)
{
int t;
/***************found***************/
t=x;x=y;
/***************found***************/
return(y);
}
main( )
{int a=3,b=8;
clrscr( );
printf("%d %d/n",a, b);
b=fun(&a,b);
printf("%d %d/n" ,a,b);
}
[简答题]下列给定程序中,函数fun的功能是:实现两个变量值的交换,规定不允许增加语句和表达式。
例如,变量a中的值原为8,b中的值原为3,程序运行后a中的值为3,b中的值为8。
请改正程序中的错误,使它得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
int fun(int*x,int Y)
int f;
/*******found********/
t=x;x=y;
/********found********/
return(y);
void main( )
int a=3,b=8;
system("CLS");
printf("%d%d/n",a,b);
b=fun(&a,b);
printf("%d%d/n",a,b);
[填空题]下列给定程序中函数fun( )的功能是:求出字符串中最后一次出现的子字符串的地址,通过函数值返回,在主函数中输出从此地址开始的字符串;若未找到,则函数值为NULL。例如,当字符串中的内容为abcdabfabcdx,t中的内容为ab时,输出结果应是abcdx。当字符串中的内容为abcdabfabcdx,t中的内容为abd时,则程序输出未找到的信息:Not found!
请改正程序中的错误,使它能得出正确的结果。
注意;不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdio.h>
#include <conio.h>
#include <string.h>
char *fun(char *s,char *t)
{
char *p,*r,*a;
/*************found**************/
a=Null;
while(*s)
{ p=s;r=t;
while(*r)
/*************found**************/
if(r= =p) {r++;p++;}
else break;
if(*r==’/0’) a=s;
s++;
}
return a;
}
main( )
{char s[100],t[100],,*p;
clrscr( );
printf("/nPlease enter string S: ");
scanf("%s",s);
printf("/nPlease enter substring t: ");
scanf("%s",t);
p=fun(S,t);
if(p) printf("/nThe result is:%s/n",p);
else printf("/nNot found!/n ");
}
[填空题]下列给定程序中,函数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的功能是:把从主函数中输入的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的功能是:计算正整数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以内最大的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的功能是:求出s所指字符串中最后一次出现的t所指字符串的地址,并通过函数值返回,在主函数中输出从此地址开始的字符串;若未找到,则函数值为NULL。
例如,当字符串中的内容为“123dabf123dx”,t中内容为“ab”时,输出结果应是“123dx”。
当字符串中的内容为“123dabf123dx”,t中内容为“abd”时,则程序输出未找到信息“Not found!”。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<string.h>
char*fun(char*s,char*t)
char*p,*r,*a;
/************found*********/
a=Null;
while(*s)
p=s;r=t;
while(*r)
/************found**********/
if(r==p)r++;p++;
else break;
if(*r==’/0’)a=s;
s++;
return a;
voidmain( )
char s[100],t[100],*p;
printf("/nPlease enter string S:");
scanf("%s",s);
printf("/nPlease enter substring t=t:");
scanf("%s",t);
p=fun(s,t);
if(p)
printf("inThe result is:%s/n",p);
else
printf("inNot found!/n");