Complement: Using Boolean constant to calculate prime number algorithm

Source: Internet
Author: User

Enter the code:

/**copyright (c) 2014, College of Computer and Control engineering, Yantai University *all rights reserved.* file name: sum123.cpp*    Creator: Lin Haiyun * Completion date: December 26, 2014 * Version number: v2.0** Problem Description: Enter a number of positive integers to output the primes. * Program input: Number of indeterminate positive integers * program output: Prime numbers in output data */#include <iostream> #include <cmath>using namespace std;bool isprime (int n ); int main () {    int n;    while (Cin>>n)    {        if (IsPrime (n))            cout<<n<< "";    }    return 0;} BOOL IsPrime (int n) {    bool prime=true;    int K=int (sqrt (n));    for (int i=2;i<=k;i++)    {        if (n%i==0)        {            prime=false;            break;        }    }    return prime;}

Operation Result:


Summarize:

This knowledge point is a vacancy, has not done this knowledge point of practice. The exam only then know, now Add.

Complement: Using Boolean constant to calculate prime number algorithm

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.