zoukankan      html  css  js  c++  java
  • 判断n是否为质数

    #include <iostream>
    #include <vector>
    #include <stdio.h>
    using namespace std;
    int main()
    {
        bool judg = true;
        int i;
        while (cin >> i)
        {
            if (i < 1)
            {
                cout << "请输入1以上的值" << endl;
                continue;
            }
    
            if (i == 1)
            {
                cout << i << "是质数" << endl;
                continue;
            }
    
            else if (i == 2)
            {
                cout << i << "不是质数" << endl;
                continue;
            }
    
            else if (i == 3)
            {
                cout << i << "是质数" << endl;
                continue;
            }
    
    
            for (int j = 2; j <= i / 2; j++)
            {
                if (i%j == 0)
                {
                    judg = false;
                    break;
                }
    
            }
            if (judg)
            {
                cout << i << "是质数" << endl;
            }
            else
            {
                cout << i << "不是质数" << endl;
                judg = true;
            }
    
        }
        system("pause");
        return 0;
    }
    step by step.
  • 相关阅读:
    UVA
    codeforces #371div2 B
    POJ-3278 Catch That Cow
    巴士博弈
    权势二进制
    HDU
    SQL 函数
    SQL 查询语句×45
    SQL 触发器
    SQL 连接查询
  • 原文地址:https://www.cnblogs.com/answer727/p/7440994.html
Copyright © 2011-2022 走看看