English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

the question is wiritng a c++ code for printing all prime numbers between any 2 numbers( those two numbers are included.example:
input :
103
110
output :
103, 107 )
. please not use cout, cin and getch() our library does not include those codes :D thnx for helping ...

2007-12-03 04:15:22 · 2 answers · asked by talafay 1 in Education & Reference Homework Help

2 answers

This function might be helpful:

bool isPrime ( int p ){ // p is the candidate
bool result = true; // we assume that p is prime
if ( i < 2 ){
result = false; // if p is less than 2, it's not prime
}
else{
for(int i = 2; i < p; ++p){
if (p%i==0){ // if p is evenly divisible by anything.
result = false; // it's not prime
break;
}
}
return result;
}

In your main program, loop from the first number to the second. Use the function to determine whether or not the value is prime. HTH...

2007-12-03 04:21:30 · answer #1 · answered by jgoulden 7 · 0 0

this is authentic that in case you create an empty C++ console project and manually rename your cpp report to furnish it .c extension, seen Studio *will* execute the Microsoft C compiler, whether this is a doubly-out of date 1989 C compiler. Microsoft abandoned C a protracted time in the past. in case you % to stay with this IDE and collect C, substitute the underlying compiler. Intel C/C++ is a sturdy decision.

2016-09-30 12:32:08 · answer #2 · answered by gaub 4 · 0 0

fedest.com, questions and answers