程序填空完成功能:求分数序列2/1,3/2,5/3,8/5,13/8 ……的前20项之和。 #include <iostream> using namespace std; int main() { double i,n=1,m=1,t,s=0 ; for (i=1;i<=20;i++) { t = n ; n = m ; 【 】; s = s + m/n ; } cout<<s<<endl; return 0; }
第1题:
有以下程序: #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=10
B.n=5
C.n=20
D.n=15
第2题:
若有以下程序:#include <iostream>using namespace std;int f(){ static int i = O; ints= 1; s+=i; i++; return s;}int main(){ int i, a =0; for(i=0;i<5;i++) a+=f(); cout<<a<<end1; return 0;}程序运行后,输出的结果是( )。
A.20
B.24
C.25
D.15
第3题:
有以下程序: #include <iostream> using namespace std; int main ( ) { int n[3],i,j,k = 2; for(i = 0;i<k;i++) n[i] = O; for(i = O;i<k;i++) { for(j = O;j<k;j++) n[j] = n[i] + 1; } cout<<n [0 ] <<end1; return 0; } 上述程序运行后,输出结果是( )。
A.0
B.1
C.2
D.3
第4题:
若有以下程序: #include<iostream> using namespace std; int f() { static int i=O; int s=1; s+=i; i++; return s; } int main() { int i,a=0; for(i=0;i<5;i++) a+=f(); cout<<a<<endl; retrun 0; } 程序运行后,输出的结果是
A.20
B.24
C.25
D.15
第5题:
若有以下程序: #include <iostream> using namespace std; int f() { static int i = 0; ints= 1; s+=i; i++; return s; } int main() { int i,a = 0; for(i = 0;i<5;i++) a+=f(); cout<<a<<endl; return 0; } 程序运行后,输出的结果是
A.20
B.24
C.25
D.15
第6题:
以下程序的输出结果是
#include<iostream.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;}
}
void main( )
{ int b[10] ={1,2,3,4,5,6,7,8,9,10};int i,s=0;
reverse(b,8) ;
for(i=6;i<10;i++) s+=b[i] ;
cout < < S;
}
A.22
B.10
C.34
D.30
第7题:
假定n=3,,下列程序的运行结果是( )。 #include<iostream.h> int Fun(int m) void main() { cout<<"Please input a number:"; int n,s=0; cin>>n; s=Fun(n); cout<<s<<endl; } int Fun(int m) { iht p=1,s=0; for (int I=1;I<=m;I++) { p*=I; S+=p; } return s; }
A.7
B.9
C.8
D.10
第8题:
有如下程序: #include<iostream> using namespace std; int s=0; class sample { static int n; public: sample(int i) { n=i; } static void add() { s+=n; } }; int sample::s=0; int main() { sample a(2),b(5); sample::add(); cout<<s<<endl; return 0; } 程序运行后的输出结果是
A.2
B.5
C.7
D.3
第9题:
有以下程序: #include <iostream> using namespace std; class sample { private: int n; public: sample(){} sample(int m) { n=m; } void addvalue(int m) { sample s; s.n=n+m; *this=s; } void disp () { cout<<"n="<<n<<endl; } }; int main() { sample s (10); s.addvalue(5); s.disp(); return 0; } 程序运行后的输出结果是
A.n=10
B.n=5
C.n=15
D.n=20
第10题:
若有如下程序: #include<iostream> using namespace std; int s=0; class sample { static int n; pubic: sample(int i) { n=i; } static void add() { S+=n; } }; int sample::n=O; int main() { sample a(2),b(5); sample::add(); cout<<s<<endl; return 0; } 程序运行后的输出结果是( )。
A.2
B.5
C.7
D.3
第11题:
有以下程序: #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=10
B.n=5
C.n=20
D.n=15
第12题:
下面程序的功能是( )。 #include <iostream> #include <string> using namespace std; int main () { int i=1, n=0; char s[80],*p; p=s; strcpy(p,"It is a book.."); for (; *p !=' \0' ;p++) { if(*p=='') i=0; else if (i==0) { n++; i=1; } } cout<<"n=" <<n<<end1; return 0; }
A.统计字符串中的单词个数
B.统计字符串中的空格个数
C.统计字符串中的字母个数
D.统计字符串中的全部字符个数
第13题:
以下程序的输出结果是 #include<iostream.h> void reverse(int a[],int n) { int i ,t; for(i=0;<n/2;i++) { t=a[i]=a[i] =a[n-1-i];a[n-1-i]=t;} } void main() { int b[10]={1,2,3,4,5,6,7,8,9,10};int i,s=0; reverse(b,8); for(i=6;i<10;i++)s+=b[i]; cout<<s; }
A.22
B.10
C.34
D.30
第14题:
以下程序的输出结果是 ( )。 #include <iostream> using namespace std; int f(int b[],int m, int n) { int i,s = O; for(i = m;i<n;i+=2) s+=b [i]; return s; } int main ( ) { int x a[] = {1,2,3,4,5,6,7,8,9}; x = f(a,3,7); cout<<x<<end1; return 0; }
A.10
B.18
C.8
D.15
第15题:
若有以下程序: #include <iostream> using namespace std; int f() { static int i = 0; int s = 1; s+=i; i++; return s; } int main() { int i,a = 0; for(i = 0;i<5;i++) a+=f(); cout<<a<<endl; return 0; } 程序运行后,输出的结果是
A.20
B.24
C.25
D.15
第16题:
以下程序的输出结果是 #include<iostream.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;} } void main( ) {int b[10]={1,2,3,4,5,6,7,8,9,10};int i,s=0; reverse(b,8); for(i=6;i<10;i++)s+=b[i]; cout << S; }
A.22
B.10
C.34
D.30
第17题:
假定有如下程序: #include <iostream> using namespace std; int s =0; class example{ static int n; public: example(int i){ n=i; } static void add( ){ s+=n; } }; int example::n=0; int main( ){ example a(2),b(5); example::add(); cout<<s<<endl; return 0; }程序运行后输出结果为( )。
A.2
B.3
C.7
D.5
第18题:
以下程序的输出是【 】。
include<iostream>
using namespace std;
fun(intm)
{
static int n=1;
n=m*n;
return(n);
}
void main()
{
int i;
for(i=1;i<=3;i++) cout<<fun(i);
}
第19题:
有以下程序: #include <iostream> using namespace std; class sample { private: iht n; public: sample(){} sample(int m) { n=m; } void addvalue(int m) { sample s; s.n=n+m; *this=s; } void disp() { cout<<"n="<<n<<end1; } }; int main() { sample s(10); s.addvalue(5); s.disp(); return 0; } 程序运行后的输出结果是
A.n=10
B.n=5
C.n=15
D.n=20
第20题:
下面程序的输出结果是( )。 #include <iostream> using namespace std; void main( ) int i,j,m=0,n=0; for(i=0;i<2;i++) for(j=0;j<2;j++) if(j> =i) m=1;n++; cout<<m<<endl; cout<<n;
A.1 1
B.1 4
C.1 6
D.0 2
第21题:
若有以下程序: #include<iostream> using namespace std; int fun() { static int i=0; int s=1; s+=i; i++; return s; } int main() { int i,a=0; for(i=0;i<5;i++) a+=fun(); cout<<a<<endl; return 0; } 程序运行后,输出的结果是( )。
A.20
B.24
C.26
D.15
第22题:
有以下程序:#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=10
B.n=5
C.n=20
D.n=15
第23题:
若有如下程序: #include<iostream> using namespace std; int s=0; class sample { static int n; public: sample(int i) { n=i; } static void add() { S+=n; } }; int sample::n=0; int main() { sample a(2),b(5); sample::add(); cout<<s<<endl; return 0; } 程序运行后的输出结果是( )。
A.2
B.5
C.7
D.3
第24题:
若有如下程序: #include <iostream> using namespaces std; int s=0; class sample { static iht n; public: sample(int i) { n=i; } static void add() { s+=n; } }; int sample::s=0; int main() { sample a(2),b(5); sample::add(); cout<<s<<endl; return 0; } 程序运行后的输出结果是
A.2
B.5
C.7
D.3