x2311

Untitled

Jun 7th, 2022
787
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. int main()
  10. {
  11.     // creat array numbers
  12.     vector<int> a;
  13.     // open file in read mode
  14.     fstream file("input_number.txt", ios::in);
  15.     if(!file.is_open()) return -1;
  16.  
  17.     string number;
  18.  
  19.     // read all numbers with numbers.txt
  20.     while(getline(file, number, ' ')){
  21.         a.push_back(stoi(number));
  22.     }
  23.     file.close();
  24.  
  25.     // open file in write mode
  26.     file.open("output_number.txt", ios::out);
  27.     if(!file.is_open()) return -2;
  28.  
  29.     // write down real numbers b
  30.     float f;
  31.     for(int i = 2; i < int(a.size()); i++){
  32.         f = 0;
  33.         for(int j = 0; j <= i; j++){
  34.             f += a[j];
  35.         }
  36.         f = a[i]/(1 + f * f);
  37.         file << f << ' ';
  38.     }
  39.     file.close();
  40.     return 0;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment