-------------------------------------------------- 注意:部分源程序给出如下。请勿改动主函数main和其它 函数中的任何内容,仅在函数的花括号中填入所编 写的若干语句。
--------------------------------------------------*/
#include
int sofd(int n) {
/**********Program**********/
/********** End **********/ }
int main() {
cout<<\
//忽略阅读
grading(); //忽略阅读结束
return 0; }
//以下忽略阅读 void grading() {
int n, i;
fstream infile,outfile; infile.open(\ outfile.open(\ for (i=0;i<10;i++) {
infile>>n;
outfile< infile.close(); outfile.close(); } 答案: int m,s = 0; 第30题 (10.0分) 题号:726 /*------------------------------------------------ 【程序设计】 -------------------------------------------------- 题目:请编写一段代码,求出给定正整数s的所有因子, 并按从小到大的顺序存放在数组factor中。 例如:24的因子是1、2、3、4、6、8和12,因子个数是7。 -------------------------------------------------- 注意:部分源程序给出如下。仅在标有\和\ 的注释行之间补充代码,请勿改动其它内容。 ------------------------------------------------*/ #include void grading(int factor[],int n); int main() { int s=336; int *factor=new int[s/2]; //动态分配s/2个整数存储空间 int count=0; /**********Program**********/ while(n!=0) { } return s; m=n; s+=m; n=n/10; /********** End **********/ for(int i=0;i //忽略阅读 grading(factor, count); delete []factor; //忽略阅读结束 return 0; } //以下忽略阅读 void grading(int factor[],int n) { fstream myfile; myfile.open(\ if(!myfile) { cout<<\无法打开数据文件out.txt,需核查。\ return; } for(int i=0;i myfile << factor[i] << \ myfile << endl; myfile.close(); } 答案: for(int j=1;j<=s/2;j++) { if(s%j==0) { } factor[count]=j; count++; } 第31题 (10.0分) 题号:615 /*------------------------------------------------ 【程序设计】 -------------------------------------------------- 题目:请编写函数int find(int n),判断整数n是否满足 下面的条件:n加上100后是一个完全平方数,n再 加上168又是一个完全平方数。若满足条件,函数 返回整数n;否则返回0。 说明:如果一个整数n是另一个整数的平方,则称整数n是 完全平方数。例如81是9的平方,则81是完全平方数。 -------------------------------------------------- 注意:部分源程序给出如下。请勿改动主函数main和其它 函数中的任何内容,仅在函数的花括号中填入所编 写的若干语句。 ------------------------------------------------*/ #include int find(int n) { /**********Program**********/ /********** End **********/ } int main() { int i,z; for (i=1;i<1000;i++) { z=find(i); if (z!=0) cout << z < //忽略阅读 grading(); //忽略阅读结束 return 0; } //以下忽略阅读 int grading() { int d; fstream infile, outfile; infile.open(\ outfile.open(\ for (int i=0;i<8;i++) { infile >> d; outfile << find(d) << endl; } infile.close(); outfile.close(); return 0; } 答案: int x,y, result; 第32题 (10.0分) 题号:696 /*------------------------------------------------ return result; x=sqrt(n+100); /*x为n加上100后开方后的结果*/ y=sqrt(n+268); /*y为n再加上168后开方后的结果*/ if(x*x==n+100 && y*y==n+268) result = n; result=0;