1~100사이의 모든 소수를 구하는 프로그램인데 내가 한 거(2번째 꺼)는 안 됨. ㅠ 

첫 번째 코드는 잘 작동하는데, 두 번째 코드는 빌드하고 실행은 되는데 콘솔에서 검은 화면만 뜸.

이거 안되는 이유가 뭐임??

헤더 파일 : https://pgh268400.tistory.com/439


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "std_lib_facilities.h"
 
vector<int> prime;
bool is_prime(int n)
{
    for (int p = 0; p < prime.size(); ++p)
        if (n % prime[p] == 0) return false;
    return true;
}
 
int main()
{
    prime.push_back(2);
    for (int i = 3; i < 100; ++i) {
        if (is_prime(i)) prime.push_back(i);
    }
    cout << "Primes: ";
    for (int x : prime) {
        cout << x << '\n';
    }
}
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "std_lib_facilities.h"
 
int main()
{
    vector<int> prime = { 2 };
    for (int i = 3; i < 101; ++i)
        for (int p = 0; p < prime.size(); ++p)
            if (i % prime[p] != 0)
                prime.push_back(i);
    cout << "Primes: ";
    for (int x : prime)
        cout << x << '\n';
}
 
cs