Answer to Question #24475 in C++ for arem marcial

Question #24475
Write a program that read 10 integers (in inPrime.txt) and output all the prime numbers in (outPrime.txt)
1
Expert's answer
2013-02-19T09:46:33-0500
#include <iostream>
#include <fstream>
using namespace std;

bool isPrime(int x) {
if (x==1)return false;
else {
boolg=true;
for (inti=2; i*i<=x; i++)
if(x%i==0) {
g=false;
break;
}
return g;
}
}

int main() {
ifstreamin("inPrime.txt");
ofstreamout("outPrime.txt");
for (int i=0;i<10; i++) {
int x;
in>> x;
if (isPrime(x))
out<< x << " ";
}
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!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS