c++编程,关于回数和质数。

来源:百度知道 编辑:UC知道 时间:2024/06/28 05:10:25
Problem Description
Palindromes are words or numbers that are read the same forwards and backwards. For example: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111, 121 are palindrome numbers.
Prime numbers are the numbers that are dividable by only one and by themselves. For example: 1, 2, 3, 5, 7, 11, 13, 17, 19, 23 are prime numbers.
Develop an algorithm and then translate it to a C++ program to prompt user for an integer number, N. Then it prints out all prime palindrome numbers less that N.
For example: 1, 2, 3, 5, 7, 11, 101 are all palindrome prime numbers less than 102.
Use top-down design, and divide the problem into appropriate sub-task like we did in the class. Then translate them into C++ functions.

Note 1: You should develop at least four functions. The body of the main program should be very simple, and it should call appropriate functions to do the task.
Note 2: We have not studied Strings and arrays yet, s

不是什么难事吧
它只不过要求 不用数组,不用字符串
必须用函数,函数放在头文件里面,要求调用

不用数组确实麻烦。。。
建立头文件,在里面做两个函数,两个函数都只有一个参数,返回值可以是0/1,也可以是别的 ,你自己看着办
函数1实现:检查一个数是不是回数,用求余的方法算,看首位跟末位是不是一样,一样就是,不一样就不是,函数返回一个数,确认输入的这个参数到底是不是回数
函数2实现:检查一个数是不是素数,这个就不用我说了吧

最后建立 主函数 调用原来那个头文件
主函数里面一个循环, 1--N
用两个函数一个一个查看,都符合条件的就是所需要的数

完成。。。。。要是用数组 或许思路清晰一点

c+课本上有,你自己查去

给个链接