4、一个交换两个浮点数的函数swap,并在主函数中调用这个 函数进行两个浮点数的交换,但结果未正确输出,只修改哪一行代码来使程序正确 Void swap(float a,float b) { float temp=a; a=b; b=temp; } void main() { float a=1,b=2; swap (a, b ); }A.第1行B.第2行C.第4行D.第6行

4、一个交换两个浮点数的函数swap,并在主函数中调用这个 函数进行两个浮点数的交换,但结果未正确输出,只修改哪一行代码来使程序正确 Void swap(float a,float b) { float temp=a; a=b; b=temp; } void main() { float a=1,b=2; swap (a, b ); }

A.第1行

B.第2行

C.第4行

D.第6行


参考答案和解析
第 1行

相关考题:

若各选项中所用变量已正确定义,函数 fun 中通过 return 语句返回一个函数值,以下选项中错误的程序是A)main(){ …… x=fun(2,10); …… }float fun(int a,int b){ …… }B)float fun(int a,int b){ …… }main(){ …… x=fun(i,j); …… }C)float fun(int,int);main(){ …… x=fun(2,10); …… }float fun(int a,int b) { …… }D)main(){ float fun(int i,int j);…… x=fun(i,j); …… }float fun(int a,int b){ …… }

下面程序的运行结果为#includevoid swap(int a,int b{int temp;temp=a++;a=b;b=temp;}void main(){int a=2,b=3;swap(a,b):cout }A.2,3B.3,2C.2,2D.3,3

下面程序的运行结果为 include void swap(int a, int b) { int temp; temp=a 下面程序的运行结果为#include<iostream.h>void swap(int a, int b){int temp;temp=a++;a=b;b=temp;}void main( )int a=2,b=3;swap(a, b) ;cout < < a < <"," < < b < < endl;}A.2,3B.3,2C.2,2D.3,3

下面程序的运行结果为()。includevoid swap(int a,int B) {int temp;temp=a++; 下面程序的运行结果为( )。 #include<iostream.h> void swap(int a,int B) { int temp; temp=a++; a=b; b=temp; } void main() { int a=2,b=3; swap(a,b); cout<<a<<“,”<<b<<end1; }A.2,3B.3,2C.2,2D.3,3

下列程序的招待结果是【 】。 include float temp;float fn2(float r){ temp=r* 下列程序的招待结果是【 】。include <iostream. h>float temp;float fn2(float r){temp=r* r* 3.14;return temp;}void main( ){float a=fn2(5.0);float b=fn2(5.0)b=20;cout<<temp<<end1;}

下面各被调用函数首部书写正确的是( )A.void sub(float x;float y);B.void sub(float x,y)C.void sub(float x,float y)D.void sub(float x,float y);

阅读以下说明和C语言函数,将应填入(n)处的字句写在对应栏内。[说明]编写一个函数,输入为偶数时,调用函数求1/2+?/+…+1/n,当输入n为奇数时,调用函数1/1+1/3+…+1/n (利用指针函数)。[函数]include "stdio. h",main(){float peven (),podd (),dcall ();float sum;int n;while (1){scanf("%d",n);if (n>1)break;}if(n%2==0){printf("Even="):(1);}else{pfinff("Odd=");(2);}printf("%f",sum);}float peven (int n){float s;int is=1;for(i=2;i<=n;i+=2)(3);return (s);}float podd (n)int n;{float s;int i;s=0;for(i=1 i<=n;i+=2)(4);return (s);}float dcall(fp,n)float (*fp) ();int n;{float s;(5);returu (s);}

下列程序的执行结果是______。 include float temp; floatfn2(float r) { temp= 下列程序的执行结果是______。include<iostream.h>float temp;floatfn2(float r){temp=r*r*3.14;return temp;}void main( ){float a=fn2(5.0);floatb=fn2(5.0);b=20;cout<<temp<<endl;}

下面程序应能对两个整型变量的值进行交换。以下正确的说法是 include void swap 下面程序应能对两个整型变量的值进行交换。以下正确的说法是 #include<iostream.h> void swap(int p,int q) { int t; t=p; p=q; q=t;} void main( ) { int a=10,b=20; cout<<a<<" "<<b; swap(a,b); cout<<a<<" "<<b;}A.该程序完全正确B.该程序有错,只要将语句swap(a,b);中的参数改为a,b即可C.该程序有错,只要将swap( )函数中的形参p和q以及t均定义为指针(执行语句不变)即可D.以上说法都不对

下面程序的输出结果是()。includeusing namespace std;void swap(int x[2]){int t; t= 下面程序的输出结果是( )。 #include<iostream> using namespace std; void swap(int x[2]) { int t; t=x[0]; x[0]=x[1]; x[1]=t; } void main() { int a[2]={4,8}; swap(a); cout<<a[0]<<" "<<a[1]; }A.4 8B.8 4C.4 4D.8 8

下面程序输出的结果是( )。 include using namespace std; void swap(int 下面程序输出的结果是( )。 #include <iostream> using namespace std; void swap(int a,int b){ int temp; temp=a; a=b; b=temp; } void main(){ int x=2; int y=3; swap(x,y); cout<<x<<y; }A.23B.32C.abD.ba

有下列函数定义: fun(float h) { printf(%f,%f\n,h,h*h);) 该函数的类型是( )。A.int类型B.float类型C.void类型D.函数无类型说明,定义有错

有下列函数定义: fun(float h) { printf("%f,%f\n",h,h*h);) 该函数的类型是( )。A.int类型SX 有下列函数定义: fun(float h) { printf("%f,%f\n",h,h*h);) 该函数的类型是( )。A.int类型B.float类型C.void类型D.函数无类型说明,定义有错

对于函数原型void function(int x,float y,char z='a'),合法的函数调用是( )。A.function(2,3.Of)B.function(2,3,4)C.function(2)D.function()

以下4个程序中,不能实现两个实参值进行交换的是 ( )。A.void swap (float *p, float *q) { float *t ,a; t = a; t = p; *p = *q; *q = *t; } void main () { float x = 8.0;y = 9.0; swap (x, y); cout<<x<<", "<<y<<B.void swap (float *p, float *q) { float a; a = *p; *p = *q; *q = a; } void main() { float x = 8.0;y = 9.0; swap (x, y); cout<<x<<", "<<y<<end1;C.void swap (float *p, float *q) { float x; x = *p; *p = *q; *q = x; } void main() { float a,b.; *a = 8.0;*b = 9.0; swap (a, b) ;D.void swap (float p, float q) { float a; a = p; p = q; q = a; } void main() { float a = 8.0,b = 9.0; swap (a,b); cout<<x<<", "<<y<<

以下程序的输出结果是 void fun(float*p1,float*p2,float*s) { s=(float*)calloc(1,sizeof(float)); *s=*p1+*p2++;} main() { float a[2]={1.1,2.2},b[2]={10.0,20.0},*s=a; fun(a,b,s); printf("%5.2f\n",*s);}A.11.1B.12C.21.1D.1.1

下面程序的运行结果为( )。 #includeiostream.h void swap(int&a,int B. int temp; temp=a++: a=b: b=temp; } void main { im a=2,b=3; swap(a,B.; eouta”,”bendl; }A.2,3B.3,2C.2,2D.3,3

若各选项中所有变量已正确定义,函数fun中通过return语句返回一个函数值,以下选项中错误的程序是______。A.mam() {…… x=fun(2,10); ……} fioat fun(int a,int b) { ……}B.float fun (int a,int b) {……} main() {…… x=fun(i,j); ……}C.float fun (int int); main() {…… x=fun(2,10); ……} float fun (int a,int b){ ……}D.main() { float fun (int i, int j); …… x=fun(i,j); ……} float fun (int a,int b){ ……}

下面程序的执行结果是()。includeusing namespace std;class building {public:buildi 下面程序的执行结果是( )。 #include<iostream> using namespace std; class building { public: building() {} building(unsigned stories, float breadths, float lengths) { story = stories; breadth = breadths; length = lengths;} void getstory(void) { cout<<"story is:"<<story<<endl;} void getarea(void) { area = length*breadth*story;cout<<"area is:"<<area<<endl;} private: unsigned story; float length; float breadth; float area; }; void main(void) { building b1,b2;building b3(10u,16.6,58.8); b1.getstory(); b1.getarea(); b2.getstory(); b2.getarea(); b3.getstory(); b3.getarea();}A.story is:0 area is:0 story is:0 area is:0 story is:10 area is:9760.8B.story is:null area is:null story is:null area is:null story is:10 area is:9760.8C.前两个对象输出的结果是不定的,后一个对象的结果正确D.前两个对象没有初值,因此程序编译时出错

下面程序的运行结果为includeVoid swap(int a,int b){int temp;temp=a++;a=b; 下面程序的运行结果为 #include<iostream,h> Void swap(int a,int b) { int temp; temp=a++; a=b; b=temp; } void main() { int a=2,b=3; swap(a,b); cout <<a <<”,” <<b <<end1 }A.2,3B.3,2C.2,2D.3,3

下列重载函数中,正确的是( )。A.void fun(int a,float b);void fun(int C,float d)B.void fun(int a,float b);void fun(float a,int b)C.float fun(int a,float b);int fun(int b,float a)D.int fun(int a,int b);float fun(int a,int b)

对下面的程序,说法正确的是()。includeusing namespace std;void sum(float m, float 对下面的程序,说法正确的是( )。 #include<iostream> using namespace std; void sum(float m, float n) { float sum=m+n; } main() { cout<<sum(5.3,6.5)<<endl;}A.该程序是错误的,错误之处在于没有对sum()函数进行说明B.程序书写规整,无语法错误,是正确的C.该程序语法无错误,但在调用函数sum()时出错,因为sum()函数被定义为viod类型,但却被主函数调用,因而是错误的D.虽然sun()函数被定义为void类型,但调用时也不会出错,程序能够编译通过

下面程序的运行结果为( )。 include using namespace std; void swap(int a,int b){ int temp; temp=a; a=b; b=temp; } void main(){ int a=2,b=3; swap(a,b); cout<<a<<"," <<b<<ENDL; }A.2,3B.3,2C.2,2D.3,3

若下列各选项中所有变量已正确定义,函数fun通过return语句返回一个函数值,以下选项中错误的程序是( )。A.main( ) {...... x = fun(2,10);......} float fun(int a, int b){......}B.float fun( int a,int b){......} main( ) {......x = fun(i,j);......}C.float fun(int, int); main( ) {......x=fun(2,10);......} float fun(iht a, int b){......}D.main( ) { float fun(int i, int j); ...... x = fun(i,j);......} float fun(int a,int b) {......}

自定义函数fact的功能是计算k的阶乘,函数原型可以写作“floatfact(int)”。按照以下各小题的要求写出相应的函数原型。 ⑴自定义函数f1的功能是计算平面上任意两点之间的距离。 ⑵自定义函数swap的功能是交换调用函数中两个float类型实参变量的值。

单选题下列重载函数中,正确的是(  )。Avoid fun(int a,float b);void fun(int C,float d)Bvoid fun(int a,float b);void fun(float a,int b)Cfloat fun(int a,float b);int fun(int b,float a)Dint fun(int a,int b);float fun(int a,int b)

问答题请根据以下各小题的要求设计C应用程序(包括界面和代码)。  下列给定的程序中,函数fun的功能是:把主函数中输入的3个数,最大的放在a中,最小的放在c中。例如,输入的数为55 12 34,输出结果应当是:a=55.0,b=34.0,c=12.0。  请改正程序中的错误,使它能得到正确结果。  注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。  试题程序如下:#include #include void fun(float *p,float *q,float *s){ float *k; k = (float *)malloc(sizeof(float)); if(*p*q) {  /**********found**********/  k=*p;*p=*q;*q=k; } /**********found**********/ if(*s*p) {  /**********found**********/  k=*s; *s=*p; *p=k; } if(*q*s) {  /**********found**********/  k=*q; *q=*s; *s=k; } free(k);}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,a,b,c); fun(a,b,c); printf(a = %4.1f, b = %4.1f, c = %4.1f,a,b,c);}

单选题已知主函数中通过如下语句序列实现对函数模板swap的调用:int a[10],b[10];swap(a,b,10);下列对函数模板swap的声明中,会导致上述语句序列发生编译错误的是(  )。Atemplatetypename Tvoid swap(T a[],T b[],int size);Btemplatetypename Tvoid swap(int size,T a[],T b[]);Ctemplatetypename T1,typename T2void swap(T1 a[],T2 b[],int size);Dtemplateclass T1,class T2void swap(T1 all,T2 b[],int size);