C++ 编程思想 第三章 3-2

#include <iostream>
#include <cmath>    // for sqrt()
using namespace std;

#define MAX 100
//质数
int main()
{
    cout << "2";
    int i;
    int j;
    for (i = 3; i < MAX + 1; i += 2)
    {
        for ( j = 3; j <= sqrt(i); j += 2)
        {
            if (i % j == 0)
            {
                break;
            }
            
        }
        if (j > sqrt(i))
        {
            cout << i << ' ';
        }
        

    }
    cout << endl;
    system("pause");
    return 0;
}
原文地址:https://www.cnblogs.com/jingchu/p/10053656.html