[C++] Program Bilangan Prima dengan Deret

#include <iostream>

using namespace std;

int main() {
    int x;
    cout << "Masukkan jumlah suku  : "; cin >> x;
    cout << "Deretnya              : ";

    int i = 1, y = 3;
    while(i <= x) {
        int z = 0;
        for(int j = 2; j < y; j++) {
            if(y % j == 0) {
                z = 1;
                break;
            }
        }
        if(z == 0) {
            cout << y << " ";
            i++;
        }
        y++;
    }
}


Diskusi Yuk...!

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Google

You are commenting using your Google account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

Connecting to %s