题目内容
请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2,此工程中含有一个源程序文件proj2.cpp,请编写一个函数int huiwen(int n),用于求解所有不超过200的n值,其中n的平方是具有对称性质的回文数(回文数是指一个数从左向右读与从右向左读是一样的,例如:34543和1234321都是回文数)。求解的基本思想是:首先将n的平方分解成数字保存在数组中,然后将分解后的数字倒过来再组成新的整数,比较该整数是否与n的平方相等。 注意:请勿修改主函数main和其他函数中的任何内容,只在横线处编写适当代码,也不要删除或移动“//****found****”。 //proj2.cpp #include <iostream> using namespace std; int huiwen(int n) { int arr[16], sqr, rqs=0, k=1; sqr =n*n; for(int i=1; sqr!=0; i++) { //******** found******** ______; sqr/ =10; } for(;i>1; i--) { rqs+ =arr[i-1]* k; //******** found******** ______; } //******** found******** if(______) return n; else return 0; } int main () { int count =0; cout <<"The number are: "<<endl; for(int i=10; i<200; i++) if(huiwen(i)) cout << ++count <<’\t’<<i<<’\t’<<i* i<<endl; return 0; }
查看答案
搜索结果不匹配?点我反馈