1// io/read-file-sum.cpp - Read integers from file and print sum.
2// Fred Swartz 2003-08-20
3
4#include <iostream>
5#include <iomanip>
6#include <fstream>
7using namespace std;
8
9int main() {
10 int sum = 0;
11 int x;
12 ifstream inFile;
13
14 inFile.open("test.txt");
15 if (!inFile) {
16 cout << "Unable to open file";
17 exit(1); // terminate with error
18 }
19
20 while (inFile >> x) {
21 sum = sum + x;
22 }
23
24 inFile.close();
25 cout << "Sum = " << sum << endl;
26 return 0;
27}
28
1Write a program in which, read 10 integers from a file “input.txt” into an integer array. Now display prime numbers using pointers.
2
3Input.txt: 10 2 5 7 6 8 4 9 11 13
4
5