C + + brush question--2704: palindrome prime

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.