2704: palindrome Prime number */Copyright (c) 2014, Yantai University School of Computer * All rights reserved. * File name: Test.cpp * Chen Dani * Completion date: May 26, 2015 * version number: v1.0 */description Enter a number n, output all the palindrome primes within N. Palindrome primes, that is, both prime numbers, but also palindrome number, from the past, from the back to look at the same. Example 373. Input greater than 10 positive integer noutputn all palindrome primes sample Input500sample Output2 3 5 7 101 131 151 181 191 313 353 373 383#include <iostr Eam>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: Just beginning to write to the problem, feel very simple, with a few loop statements on the line, but when they write, found to use a lot of circulation, but also prone to error, so listen to the tips of others, with the function of writing simple,
Not complicated, one can understand. So the function is a good way to solve the problem. Keep trying!
C + + brush question--2704: palindrome prime