Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- using namespace std;
- int main()
- {
- // creat array numbers
- vector<int> a;
- // open file in read mode
- fstream file("input_number.txt", ios::in);
- if(!file.is_open()) return -1;
- string number;
- // read all numbers with numbers.txt
- while(getline(file, number, ' ')){
- a.push_back(stoi(number));
- }
- file.close();
- // open file in write mode
- file.open("output_number.txt", ios::out);
- if(!file.is_open()) return -2;
- // write down real numbers b
- float f;
- for(int i = 2; i < int(a.size()); i++){
- f = 0;
- for(int j = 0; j <= i; j++){
- f += a[j];
- }
- f = a[i]/(1 + f * f);
- file << f << ' ';
- }
- file.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment