// C++ program that reads numbers from a file and calculates their sum
using namespace std;
#include <iostream>
#include <fstream>
int main() {
// Open the input file
ifstream inputFile("numbers.txt");
if (!inputFile) {
cout << "Failed to open the file." << endl;
return 1;
}
double sum = 0;
double number;
// Read numbers from the file and calculate the sum
while (inputFile >> number) {
sum += number;
}
// Close the file
inputFile.close();
// Print the sum
cout << "Sum of numbers in the file: " << sum << endl;
return 0;
}
Computer Methods in Science Course
Subscribe to:
Post Comments (Atom)
NaCl.xyz Generator with Interactive 3D Visualization
NaCl.xyz Generator with Interactive 3D Visualization NaCl.xyz Generator with Interactive 3D Visualization ...
-
In mathematics, Pascal's triangle is a triangular array of the binomial coefficients Coasters (Set of 4) $13.91 #MOVING #EYE #ILLUSION #...
-
Cognitive Science Hexagon - научные направления, которые способствовали зарождению когнитивной наукиActive T-Shirt $25.00 Baseball ¾ Sleeve T-Shirt $25.20 Classic T-Shirt $19.90 Graphic T-Shirt $28.22 Lightweight Hoodie $34.85 Lightweight S...
-
Get my art printed on awesome products. Support me at Redbubble Unit #circle #angles. #Trigonometry, #Math Formulas, Geometry Formu...
No comments:
Post a Comment