~cpp #include <iostream> using namespace std; int main() { int a; cout << "원하는 수를 입력하시오. : "; cin >> a; for(int i=2;i<=a;i++) { int count = 0; for(int j=2;j<i;j++) { if((i%j)!=0) count++; } if(count==(i-2)) cout << i << " "; } cout << endl; return 0; }
~cpp #include<iostream> using namespace std; int main() { int num; cout<<"숫자를 입력하세요:"; cin>>num; for(int k=2;k<num;k++) { int count=0; for(int i=1;i<=num;i++) { for(int j=2;j<=num;j++) { if(j*i==k) count++; } } if(count==1) cout<<k<<" "; } return 0; }
~cpp #include <iostream.h> void main() { int num; int count; cout << "숫자를 입력하시오 = "; cin >> num; if (num >= 2) cout << "2\n"; else cout << "소수가 대략 없소!\n"; for (int i = 2; i <= num; i++) { for (int j = 2; j < i; j++) { if (i % j == 0) count++; } if (count == 0) cout << i << "\n"; count = 0; } }