C ++ brush question -- 2704: Prime Number of the return text, 2704

Source: Internet
Author: User

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!

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.