Just in my curious, I try to display it on C++ language program. Awesome, not only just prime number which I can display, but also number of range which I want to display on that program also able.
I have tried this code at Dev C++, and it was running well.
#include <iostream>
using namespace std;
int main() {
int n, isprime;
cout << "Masukkan range angka : ";
cin >> n;
for (int i=2; i<= n; i++) {
isprime = 1;
for (int j=2; j<=i; j++) {
if(i==j)
continue;
else if(i%j == 0)
isprime = 0;
}
if(isprime)
cout << i << ", ";
}
system ("pause");
return 0;
}

0 komentar:
Post a Comment