单选题 C++
题号 #2607628

下面程序的运行结果是(    )。
#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:
}

进入在线模考

参考答案

C

答案解析

for循环执行2次,所以第一次for循环为result=1*a[1]=4,第二次for循环为result=4*a[2]=20。

你可能感兴趣的试题

3

请使用VC6或使用【答题】菜单打开考生文件夹progl下的工程progl,该工程中包含程序文件main. cpp,其中有Salary(“工资”)类和主函数main的定义。程序中位于每个“//ERROR ****found****”之后的一行语句行有错误,请加以改正。改正后程序的输出结果应为:
应发合计:3500应扣合计:67.5实发工资:3432.5
注意:只修改每个“//ERROR ****found****”下的那一行,不要改动程序中的其他内容。
#include<iostream>
using namespace std;  class Salary{
public:
Salary(const char *id,double the_base,double the bonus,double the_tax)    //ERROR **********found**********
:the_base(base),the_bonus(bonus),the_tax(tax)    {
staff_id=new char[strlen(id)+1];    strcpy(staff_id,id);
}
//ERROR **********found**********    ~Salary(){delete * staff_id;}
double getGmssPay()const{retum base+bonus;}//返回应发项合计
double getNetPay()const}retum getGmssPay()-tax;}//返回实发工资额  private:
char * staff id;//职工号    double base;//基本工资    double bonus;//奖金
double tax;//代扣个人所得税    };
int main(){
Salary pay(”888888”,3000.0,500.0,67.50);
cout<<”应发合计:”<<pay.getGrossPay()<<" ";
cout<<”应扣合计:”<<pay.getGrossPay()一pay.getNetPay()<<””;
//ERROR**********found**********
cout<<”实发工资:”<<pay::getNetPay()<<endl;
return 0;
}

找试题 · 找答案 · 找资料 在线模考