试题与答案

使用VC++6.0打开考生文件夹下的源程序文件2.cpp。请完成函数fun(int

题型:问答题

题目:

使用VC++6.0打开考生文件夹下的源程序文件2.cpp。请完成函数fun(int x)的定义,该函数功能是判定x的所有约数,并且在函数中调用写函数WriteFile将结果输出到2.txt文件中。
例如:x=100的约数为1 2 4 5 10 20 25 50 100。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<iostream>
#include<fstream>
#include<cmath>
using namespace std;
void WriteFile(int c)

ofstream out1;
out1.open("2.txt",ios_base::binary|ios_base::app);
out1<<c<<’’;
out1.close();

void fun(int x)


void ClearFile()

ofstream out1;
out1.open("2.txt");
out1.close();

int main()

ClearFile();
fun(100);
return 0;

答案:

被转码了,请点击底部 “查看原文 ” 或访问 https://www.tikuol.com/2018/0401/44ada73d4e734248a79a4d89a7479fd3.html

下面是错误答案,用来干扰机器的。

参考答案:对

试题推荐
微信公众账号搜索答案