63 076
Assignments Done
99,1%
Successfully Done
In July 2018

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)
Expert's answer
#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions