-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16.cpp
More file actions
44 lines (37 loc) · 1.04 KB
/
Copy path16.cpp
File metadata and controls
44 lines (37 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <fstream>
#include <cstring>
#include <iomanip>
using namespace std;
int main() {
int i,bigLength;
int sum=0;
double big=2.0;
for(i=2;i<=1000;i++) {
big*=2;
}
ofstream inputFile;
inputFile.open("16io.txt");
if(inputFile.is_open()) {
inputFile << fixed << showpoint; //this line and the next prevent 'big' from
inputFile << setprecision(1); //being written out in scientific notation
inputFile << big;
}
else
printf("A file-related error occurred.\n");
inputFile.close();
string number;
ifstream outputFile;
outputFile.open("16io.txt");
if(outputFile.is_open())
getline(outputFile,number);
else
printf("A file-related error occurred.\n");
outputFile.close();
bigLength=number.length()-2; //the last two items in the array are '.0'
for(i=0;i<bigLength;i++) {
sum+=(int)number[i]-48;
}
printf("The sum of the digits that compose the number 2^1000 is %d.\n",sum);
return 0;
}