Answer to Question #24475 in C++ for arem marcial
2013-02-15T22:39:27-05:00
Write a program that read 10 integers (in inPrime.txt) and output all the prime numbers in (outPrime.txt)
1
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 !
Learn more about our help with Assignments:
C++
Comments
Leave a comment