Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- bool cek(int i)
- {
- if(i <= 1){
- return false;
- };
- for (int j = 2; j <= i/2; ++j) {
- if(i % j == 0){
- return false;
- };
- };
- return true;
- }
- int main() {
- int input, inc = 1;
- cout<<"Masukkan Nomor : ";
- cin>>input;
- if(input <= 0){//a3
- cout<<"Bilangan Tidak Valid";//ya
- }else{//tidak
- do{
- for (int i = 1; i <= input; i++) {
- inc++;
- if(cek(i)){
- cout<<i<<" ";
- }else{
- input++;
- };
- }
- }
- while(inc <= input);
- cout<<"\nBilangan diatas adalah bilangan prima";
- };
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment