#include %26lt;iostream%26gt;
#include %26lt;cmath%26gt;
using namespace std;
int isPrime( long n) {
int i,k;
if (n%26lt;2) return 0;
k=(int)sqrt(n);
for (i=2; i%26lt;=k; i++){
if ((n%i) != 0 ) continue;
return 0;
}
return 1;
}
int main() {
long i,a,b;
do {
system("cls");
cout %26lt;%26lt;"\n\nEnter two numbers : ";
cin %26gt;%26gt; a %26gt;%26gt; b;
if (a %26gt; b) swap(a,b);
cout %26lt;%26lt;"\n\nThe prime numbers between ( and \n";
cout %26lt;%26lt; " including ) "%26lt;%26lt; a %26lt;%26lt; " and " %26lt;%26lt; b %26lt;%26lt; " are : \n\n";
for (i=a; i%26lt;=b; i++) {
if (isPrime(i)==1) printf("%d ,",i);
}
cout %26lt;%26lt; "\n\n";
system("pause");
} while (1 != 2);
return 0;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment