Question: 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
