Question #36147

generate the series of prime number in c++ program.
1

Expert's answer

2013-10-18T12:03:38-0400
#include <iostream>
using namespace std;
int main() {
    for (int i = 2; i < 100; i++) {
        bool prime = true;
        for (int j = 2; j * j <= i; j++) {
            if (i % j == 0) {
                prime = false;
                break;
            }
        }
        if (prime) cout << i << " ";
    }
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS