c++--2828: Prime Judgment

Source: Internet
Author: User
Description
Enter a positive integer greater than 1 and, if it is a prime number, output "yes", or "no" if it is not a prime number,

Input
A positive integer greater than 1

Output
Output "Yes" if the integer is a prime number, or "No" if not a prime number

/* Copyright (c) 2014, Yantai University School of Computer * All rights reserved. * File name: Test.cpp * Chen Dani * Completion date: May 20, 2015 * Version number: v1.0 * * #include <iostream> #include <cmath>using namespace Std;int is_prime (int n) {    int r;    if (n==1)        return 0;    else    {for        (r=2; r<=sqrt (n), ++r)            if (n%r==0) break                ;        if (R>SQRT (n))            return 1;}    } int main () {    int flag,n;    int is_prime (int);    cin>>n;    Flag=is_prime (n);    if (flag==1)        cout<< "yes" <<endl;    else        cout<< "No" <<endl;    return 0;}

Experience: refueling, always keep a good mood, only the power to insist on doing what they want to do!!

c++--2828: Prime Judgment

Related Article

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.