C++/알고리즘
c++ 알고리즘 소수 출력
mr.k0
2016. 4. 6. 19:31
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <iostream> using namespace std; int main(){ int input; cout<<"몇개?"; cin>>input; for (int i=2, count=0;i<=input;i++,count=0){ for(int j=1;j<=i;j++){ if (i%j == 0) count++; } if (count==2) cout<<i<<" "; } } | cs |