问答题
使用VC6打开考生文件夹下的源程序文件modi2.cpp。阅读下列函数说明和代码,完成空出部分程序。函数factor(int*des,int&length,int n)实现的功能是:将n所有因数存放到des中,通过length引用返回因数的个数,比如fator(a,length,20)执行后,则a={1,2,4,5,10,20},length=6。 注意:只能补充函数factor 0,请勿改动其他部分的内容。 #include
#define MAXNLEN 100 void factor(int*des,int&length, int n) { } void main() { int a[MAXNLEN],length; int n=20; factor(a,length,n); for(int i=0;i
【参考答案】
正确答案:length=0; for (int i=1;i<=n;i++) { if(n%i==0)//判断是否n的因数......
(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)
点击查看答案&解析
<上一题
目录
下一题>
热门
试题
问答题
使用VC6打开考生文件夹下的源程序文件modi1.cpp,但该程序运行时有错,请改正main()函数中的错误,使程序的输出结果如下: Constructor. Default constructor. Area is 12 Area is 0 Area is 12 注意:错误的语句在//********error********的下面,修改该语句即可。#include<iostream.h>class CRectangle{private: double length , width;public: CRectangle() { cout<< Defaultconstructor.\n ; } CRectangle(double 1,double w) { length=1;width=W; cout<< Constructor.\n ; } void Set(double 1,double W) { this->length=1; this->width=w; ) Void GetArea() { cout<< Area is <<length*width<<endl; } }; Void main() { CRectangle Rect1(3.0,4.0); //********error******** CRectangle Rect2(1); //********error******** CRectangle Rect3; Rect1.GetArea(); //********error******** Rect2.Set(0); Rect2.GetArea(); Rect3.GetArea();}
点击查看答案&解析
相关试题
使用VC6打开考生文件夹下的源程序文件modi...