网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

要求以下程序的功能是计算: s=1 + 1/2 + 1/3 + ... + 1/10, 但运行后输出结果错误,导致错误结果的程序行是 int main (void){ int n; float s; s=1.0; for(n=10; n>1; n--) s=s+1/n; printf("%6.4fn",s); return 0; }

A.int n; float s;

B.for(n=10; n>1; n--) s=s+1/n;

C.s=s+1/n;

D.s=1.0;


参考答案和解析
C 解析:程序中由于n为整型,所以1/n的结果始终为0,故程序最后输出的结果为0,其结果错误,原因为在表达式1/n中1和n均为整型,所以应该将1改为1.0,这样表达式1.0/n的值不为0,为该数学表达式的值,因此我们可以知道导致程序运行后输出结果错误的行为s=s+1/n;,所以,4个选项中选项C符合题意。
更多 “要求以下程序的功能是计算: s=1 + 1/2 + 1/3 + ... + 1/10, 但运行后输出结果错误,导致错误结果的程序行是 int main (void){ int n; float s; s=1.0; for(n=10; n>1; n--) s=s+1/n; printf("%6.4fn",s); return 0; }A.int n; float s;B.for(n=10; n>1; n--) s=s+1/n;C.s=s+1/n;D.s=1.0;” 相关考题
考题 下面程序的运行结果是: 【 17 】 。#include stdio.hint f(int a[],int n){ if(n1)return a[0] + f(a+1, n-1);elsereturn a[0];}main(){ int aa[10]={1,2,3,4,5,6,7,8,9,10}, s;s = f(aa+2,4); printf("%d\n", s);}

考题 ( 33 )有以下程序#include studio.hint f ( int t[],int n ) ;main{ int a[4]={1,2,3,4},s;s=f ( a,4 ) ; printf ( " %d\n " ,s ) ;}int f ( int t[],int n ){ if ( n0 ) return t[n-1]+f ( t,n-1 ) ;else return 0 ;}程序运行后的输出结果是A ) 4B ) 10C ) 14D ) 6

考题 34 ) 有以下程序#include stdio.hint f(int n);main(){ int a=3,s;s=f(a);s=s+f(a);printf("%d\n",s);}int f(int n){ static int a=1;n+=a++;return n;}程序运行以后的输出结果是A)7B)8C)9D)10

考题 以下程序的输出结果是includein[fun(int n,int *s){int n,f2;if(n==0‖n==1)*s=1;else{ 以下程序的输出结果是 #include<stdio.h> in[fun(int n,int *s) {int n,f2; if(n==0‖n==1) *s=1; else {fun(n-1,f1); fun(n-2,f2); *s=f1+f2; }} void main() { int x; fun(6,x); pfintf("\n%d",x);}A.7B.13C.9D.10

考题 有以下程序:includedstdio.hint f(int n); main( ){int a=3,s; s=f(a);s=s+f(a);printf(int f(int n);main( ){int a=3,s;s=f(a);s=s+f(a);printf(%dkn,s);}int f(int n){static int a=1;n+=a++;return n;}程序运行后的输出结果是( )。A.7B.8C.9D.10

考题 以下程序的功能是计算:。includemain(){int n; float s; s=1.0; for(n=10;n>1;n--)s=s+ 以下程序的功能是计算:。#include <stdio.h> main() { int n; float s; s=1.0; for(n=10;n>1;n--) s=s+1/n; printf("%6.4f\n",s); } 程序运行后输出结果错误,导致错误结果的程序行是( )。A.s=1.0;B.for(n=10;n>1;n--)C.s=s+1/n;D.printf("%6.4f\n",s);

考题 要求以下程序的功能是计算main () { int n; float s; S=1.0; for (n=10; n>1; n--) s=S+1/n; printf("%6.4f\n",S); } 程序运行后输出结果错误,导致错误结果的程序行是A.s=1.0;B.for(n=10;n>1;n--)C.s=s+1/n;D.prind("%6.4f\n",s);

考题 有以下程序:include using namespace std;class sample{private: int n;public: samp 有以下程序: #include <iostream> using namespace std; class sample { private: int n; public: sample(){} sample (int m) { n=m; } sample add(sample s1,sample s2) { this->n=s1.n+s2.n; return (*this); } void disp() { cout<<"n="<<n<<end1; } }; int main () { sample s1(10) ,s2(5),s3; s3.add(s1,s2); s3.disp(); return 0; } 程序运行后,输出的结果是( )。A.n=10B.n=5C.n=20D.n=15

考题 以下程序的输出结果是includelong fun(int n){ long s;if(n==1||1n==2) s=2;else s 以下程序的输出结果是 #include<iostream.h> long fun(int n) { long s; if(n==1 | | 1n==2) s=2; else s=n-fun(n-1) ; return s; } void main( ) {cout < < fun(3) ;}A.1B.2C.3D.4

考题 要求以下程序的功能是计算:s=1+1/2+1/3+…+…1/10main( ){ int n; float s;s=1.0;for(n=10;n1;n--)s=s+1/n;printf("%6.4f\n",s);}程序运行后输出结果错误,导致错误结果的程序行是A.s=1.0;B.for(n=10;n1;n--)C.s=s+1/n;D.printf("%6.4f\n",s);

考题 下面程序的运行结果是[]。include int f(int a[],int n){ if(n>1)return a[0]+f(a+1,n-1 下面程序的运行结果是[ ]。include <stdio.h>int f(int a[],int n){ if(n>1)return a[0]+f(a+1,n-1);elsereturn a[0];}main(){int aa[10]={12,3,4,5,6,7,8,9,10},s;s=f (aa+2,4); printf("%d\n",s); }

考题 以下程序运行后的输出结果是()。includevoid reverse(int a[],int n){int i,t;for(i=0; 以下程序运行后的输出结果是( )。 #include<stdio.h> void reverse(int a[],int n) {int i,t; for(i=0;i<n/2;i++) {t==a[i];a[i]=a[n-1-i];a[n-1-i]=t;} } main() {int b[10]={10,9,8,7,6,5,4,3,2,1};int i,s=0; reverse(b,10); for(i=0;i<3;i++)s+=b[i]; printf("%d\n",s); }A.27B.6C.25D.30

考题 以下程序的输出结果是 include long fun(int n) {long s;if(n=1||n=2)s=2; else s= 以下程序的输出结果是 #include<iostream.h> long fun(int n) { long s; if(n=1||n=2)s=2; else s=n-fun(n-1); return s; } void main( ) { cout<<fun(3);}A.1B.2C.3D.4

考题 要求以下程序的功能是计算main() {int n;float s; s=1.0; for(n=10;n>1;n--) s=s+1/n; pfintf("%6.4f\n",s); } 程序运行后输出结果错误,导致错误结果的程序行是A.s=1.0;B.for(n=10;n>1;n--)C.s=s+1/n;D.printf("%6.4f\n",8);

考题 以下程序的输出结果是includelong fun(int n){long s;if(n=1||n=2)s=2;else s=n-fu 以下程序的输出结果是 #include<iostream.h> long fun(int n) {long s; if(n=1||n=2) s=2; else s=n-fun(n-1): return s; } void main() {cout<<fun(3);=A.1B.2C.3D.4

考题 下面程序的运行结果是( )。 include main() {int a,s,n,m; a=2;s=0;n=1;m=1; while(m 下面程序的运行结果是( )。 include<stdio.h> main() {int a,s,n,m; a=2;s=0;n=1;m=1; while(m<=4){n=n*a;s=s+n;++m;} printf("s=%d",s); }

考题 以下程序的输出结果是()。includeint fun(int n,int *s){ int f1,f2;if(n==0||n==1)*s= 以下程序的输出结果是( )。 #include<stdio.h> int fun(int n,int *s) { int f1,f2; if(n==0||n==1) *s=1; else { fun(n-1,f1); fun(n-2,f2); *s=f1+f2; } } void main() { int x; fun(6,x); printf("\n%d" ,x);}A.7B.13C.9D.10

考题 要求以下程序的功能是计算s=1+1/2+1/3+…+1/10 main() { int n; float s; s=1.0; for(n=1O;n>1;n--) s=s+1/n; printf("%6.4f\n",s); } 程序运行后输出结果错误,导致错误结果的程序行是( )。A.s=1.0;B.for(n=1O;n>l;n--)C.s=s+1/n;D.printf("%6.4f\n",s);

考题 有以下程序#inculde stdio.hint F(int t[],int n);main(){ int a[4]=(1,2,3,4),s;s =F(a,4);printF(“%d\n”,s);}int F(int t[],int n){ iF(n0) return t[n-1]+F(t,n-1);Else return 0;}程序运行后的输出结果是A.4B.10C.14D.6

考题 有以下程序includevoid fun(float* p1,int n1,float,*p2,int n2,float* s){ int i;s=( 有以下程序 #include<stdio.h> void fun(float * p1,int n1,float,*p2,int n2,float * s) { int i; s=(float *)calloc(1,sizeof(float)); *s=0; for(i=0;i<n1;i++) *s+=*p1++; for(i=0;i<n2;i++) *s+=*p2++; } main() { float a[2]={1.1,2.2},b[3]={10.0,20.0,30.0),*s=a; fun(a,2,b,3,s); printf("%f\n",*s); } 上面程序的输出结果是( )A.60B.3.3C.63.3D.1.1

考题 有以下程序:includeint f(int t[],int n);main(){int a[4]={1,2,3,4},s;s=f(a,2);prin 有以下程序: #include<stdio.h> int f(int t[],int n); main() {int a[4]={1,2,3,4},s; s=f(a,2);printf("%d\n",s); } int f(int t[],int n) {if((n>0)(n<5))return t[n+1]+f(t,n-1); else return 0; } 程序运行后的输出结果是( )。A.4B.7C.10D.61

考题 有以下程序: #includedstdio.h int f(int n); main( ) {int a=3,s; s=f(a);s=s+f(a);printf("%dkn",s); } int f(int n) {static int a=1; n+=a++; return n; } 程序运行后的输出结果是( )。A.7B.8C.9D.10

考题 有以下程序:include using namespace std;class sample{private:intn;public:sample( 有以下程序:#include <iostream>using namespace std;class sample{private: int n;public: sample() {} sample(int m) { n=m; } sample add(sample s1,sample s2) { this->n-s1.n+s2.n; return (*this); void disp() { cout <<"n="<<n<<end1; } };int main (}{ sample s1(10),s2(5),s3; s3.add(s1,s2); s3.disp (); return 0;}程序运行后,输出的结果是A.n=10B.n=5C.n=20D.n=15

考题 有以下程序:include using namespacestd;class sample{private:int n:public:sample 有以下程序: #include <iostream> using namespace std; class sample { private: int n: public: sample () {} sample(int m) { n=m; } sample add(sample s1, sample s2) this->n=s1.n+s2.n; return (*this); } void disp () { cout <<"n="<<n<<end1; } }; int main() sample s1(1)0,s2(5),s3; s3.add(s1,s2); s3.disp(); return 0; } 程序运行后,输出的结果是A.n=10B.n=5C.n=20D.n=15

考题 要求以下程序的功能是计算:s=1+1/2+1/3+…+1/100。程序运行后输出结果错误,导致错误结果的程序行是( )。A.s=1.0;B.C.S=S+1/n;D.

考题 有以下程序: #includestdio.h int f(int t[],int n); main( ) {int a[4]={1,2,3,4},s; s=f(a,4);printf("%d\n",s); int f(int t[],int n) {if(n0)return t[n-1]+f(t,n-1); else return 0; } 程序运行后的输出结果是( )。A.4B.10C.14D.6

考题 单选题有以下程序:#include int f(int n);main(){ int a=3,s; s=f(a); s=s+f(a); printf(%d,s);}int f(int n){ static int a=1; n+=a++; return n;}程序运行以后的输出结果是(  )。A 7B 8C 9D 10

考题 单选题有以下程序:#include int f(int t[],int n);main(){ int a[4]={1,2,3,4},s; s=f(a,4); printf(%d,s);}int f(int t[],int n){ if(n0)return t[n-1]+f(t,n-1); else return 0;}程序运行后的输出结果是(  )。A 4B 10C 14D 6