Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C + + program to read a txt file and counts the amount of prime numbers in it . what i have so far is
C program to read a txt file and counts the amount of prime numbers in itwhat i have so far is incorrect.
#include
using std::cerr;
using std::cout;
using std::endl;
#include
using std::ifstream;
#include
This method is used to check if a number is prime or no
bool isPrimeint number
if number
return false;
for int i ; i number; i
if number i
return false;
return true;
Driver method to test the code
int main
ifstream input;
int num;
int count ;
input.openrandomINttxt;
if input
cerr "File cannot be opened!" endl;
exit;
input num;
while input.eof
if isPrimenum
count;
input num;
input.close;
cout "The total number of prime numbers is : count endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started