1、定义变量d1为布尔型,并赋初值为“true”,写出代码_________ 2、请写出程序运行的输出结果:_______ int a=3; int b=9; int result=0; result=a>b?a-b:b-a; Console.WriteLine(result);
第1题:
下面程序段的输出结果是( )。 public class Test { public static void main ( String[] args) { int result=0; for ( int i=1;i<=5;i++) { if ( i%2==0 ) continue; result + =i; } System. out. println ("result is " + result ); } }
A.result is 7
B.result is 8
C.result is 9
D.result is 10
第2题:
使用VC6打开考生文件夹下的工程test40_1,此工程包含一个源程序文件test40_1.cpp,但该程序运行有问题,请改正函数中的错误,使该程序的输出结果为:
The first result is 5
The second result is 2
The third result is 2
The fourth result is 6
源程序文件test40_1.cpp清单如下:
include <iostream.h>
int subtraction (int a, int b)
{
int r;
r=a-b;
/***************** found ************************/
return &r;
}
int main ()
{
int x=5, y=3, z;
z = subtraction (7,2);
cout << "The first result is "<< z << '\n';
cout << "The second result is "<< subtraction(7,subtraction (7,2)) << '\n';
/**************** found *************************/
cout << "The third result is "<< subtraction (&x,&y) << '\n';
/***************** found ************************/
z= 4 + *subtraction (x,y);
cout << "The fourth result is "<< z << '\n';
return 0;
}
第3题:
下面程序的运行结果是( )。 #include<iostream.h> intfun(inta[],int n) { int result=1; for(int i=“i<n;i++) result’resultxa[i]; return result; } void main() { inta[3]={3,4,5}; cout<<fun(a,3)<<endl; }
A.12
B.15
C.20
D.60
第4题:
假定a=3,下列程序的运行结果是( )。 #inelude<iostream.h> int fun(int n); void main() { cout<<"Please input a number:"; int a,result=0; cin>>a; result=fun(a); tout<<result<<end1; } intfun(int n) { int p=1,result=0; for(int i=1;i<=n;i++) { p*=i; result+=p; } return result; )
A.4
B.8
C.9
D.20
第5题:
下列语句中变量result的结果为( )。 public class test { public static void main(String args[ ]) { int sum=10; int r=3; int result=sum %( ++r); System.out.println(result); } }
A.3
B.10
C.2
D.4
第6题:
下面程序的运行结果是 #include<iostream.h> int fun(inta[],int n) { int result=1; for(int i=1:i<n;i++) result=result*a[i]; remm result; } void main() { int a[3]={3,4,5}; cout <<fun(a,3) <<end1; }
A.12
B.15
C.20
D.60
第7题:
1)#include
2)using namespace std;
3)int main()
4){
5)int a,b,result;
6)cout<<"please input two numbers:\n";
7)cin>>a>>b;
8)result=3*a-2*b+1;
9)cout<<"resultis"<< result<< endl;
10)}
程序的第5行中的cout表示:()
A、显示字符串
B、标准输出的流设备
C、标准输入的流设备
D、程序入口
第8题:
假定a=3,下列程序的运行结果是( )。 #include<iostream.h> int fun(int n); void main() { cout<<"Please input a number:"; int a,result=0; cin>>a; result=fun(a); cout<<result<<end1; } int fun(int n) { int p=1,result=0; for(int i=1;i<=n;i++) { p*=i; result +=p; } return result; }
A.4
B.8
C.9
D.20
第9题:
A. 0
B. 1
C. 2
D. 5
第10题:
class TestApp{ public static void main(String[] args){ System.out.println(multiply(2,3,4,5)); } public int multiply(int… nums){ int result = 1; for(int x :nums) result *= x; //result =result*x; return result; } } 2、6、24、120 程序运行后的输出是哪项?()
第11题:
cout<;<;&rdquo;Iamastudent./n”
;Iamastudent./n&rdquo;
Iamastudent.
Iamastudent./n
第12题:
14
编译错误
120
24
第13题:
根据输出结果填空完成下面程序。
include<iostream.h>
class Test
{
private:
static int val;
int a;
public:
static int func( );
void sfunc(Test &r);
};
______//初始化静态变量val
int Test::func( )
{
return val++;
}
void Test::sfunc(Test &r)
{
r.a=125;
cout<<"Result3="<<r.a;
}
void main( )
{
cout<<"Resultl="<<Test::func( )<<endl;
Test A;
cout<<"Result2="<<A.fune( )<<endl;
A. sfunc(A);
}
输出结果为:
Result1=201
Result2=202
Result3=125
第14题:
下面程序的运行结果是( )。 #include<iostream.h> int fun(int a[],int n) { int resuh=1; for(inl i=1;i<11;1‘++) result=result * a[i]; retum result; } void main int a[3]={3,4,5}: cout<<fun(a,3)<<endl: }
A.12
B.15
C.20
D.60
第15题:
下列程序段: int result; int a=17,b=6; result=(a%b>4)?a%b:a/bSystem.out.println(result); 的结果为 ( )
A.0
B.1
C.2
D.5
第16题:
下列语句片段: int result; int a=17,b=6; result=(a%b>4) ? a%b:a/b; System.out.println(result);
A.0
B.1
C.2
D.5
第17题:
以下程序执行后输出的结果是【 】。
include<iostream>
using namespace std;
int fac(int a,int b){
return(b-a)*a;
}
int main(){
int x=3,y=4,z=5,result;
result=fac(fac(x,y),fac(x,z));
cout<<result<<endl;
return 0;
}
第18题:
下面的语句片段中,变量result结果为( )。 public class Test { public static void main (String args[ ]) { int sum=0; int r=2; iht result=(sum==1?sum:r); System. out. println (result); } }
A.1
B.2
C.10
D.0
第19题:
下面程序的运行结果是 #include < iostream.h > int fun ( int a[ ],int n) { int result=1; for(int i=1;i<n;i++) result=result*a[i]; return result; } void main( ) { int a[3]={3,4,5}; cout << fun(a,
A.12
B.15
C.20
D.60
第20题:
有如下程序: public class MethLoad { public static void main(String args[]) { MethLoad classObj=new MethLoad(); classObj.methtest(4); classObj.methtest(0); } void methtest(double d) { double sum=2*d; System.out.println("The result is:"+sum); } void methtest(int n) { int sum=4*n; System.out.println("The result is:" +sum); } }程序的运行结果为( )。
A.The result is:16 The result is:0
B.The result is:0 The result is:16
C.The result is:8 The result is:0
D.The result is:0 The result is:8
第21题:
程序: class TestApp{ public static void main(String[] args){ System.out.println(multiply(2,3,4,5)); } public int multiply(int[] nums){ int result = 1; for(int x :nums) result *= x; return result; } } 程序运行后的输出是哪项?()
第22题:
class TestApp{ public static void main(String[] args){ System.out.println(multiply(2,3,4,5)); } public int multiply(int... nums){ int result=1; for(int x:nums) result*=x; return result; } } 程序运行后的输出是哪项?()
第23题:
14
编译错误
120
24
第24题:
120
24
14
编译错误