C ++ brush question -- 2704: Prime Number of the return text, 2704
2704: retrieval prime number/* Copyright (c) 2014, Emy of computer science, Yantai University * All rights reserved. * file name: test. cpp * Author: Chen Danni * completion date: January 1, May 26, 2015 * version number: v1.0 */Description enter a number n, and output all the return prime numbers within n. The prime number of the input message, that is, the prime number and the number of input messages. Example 373. Sample Input500Sample Output2 3 5 7 11 101 131 151 181 191 313 353 373 383 # include <iostream> using namespace std; bool ispalidrome (int); int main () {int n, I, j; cin> n; for (I = 1; I <n; I ++) {for (j = 2; j <I; j ++) {if (I % j = 0) break ;} if (j = I & ispalidrome (I) {cout <I <";}} return 0 ;} bool ispalidrome (int x) {int t = 0, r, m = x; while (m> 0) {r = m % 10; t = t * 10 + r; m/= 10 ;} return (t = x );}
Learning Experience: When I first wrote a question, I thought it was very simple. I just needed a few loop statements. However, when I wrote it myself, I found that many loops were used and it was easy to make mistakes, so I listened to other people's prompts and wrote it easily using functions,
Not complex. Therefore, the function is a useful solution to the problem. Continue to work!