Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <fstream>
- #include <string>
- using namespace std;
- int main()
- {
- ifstream filein;
- filein.open("a.txt");
- if (!filein)
- {
- cout << "Nieudana proba otwarcia pliku!" << endl;
- system("pause");
- return 1;
- }
- double d,temp[100] = { 0 };
- int ilosc = 0;
- while (ilosc < 100)
- {
- filein >> d;
- if (filein.eof())break;
- temp[ilosc] = d;
- cout << d << endl;
- ilosc++;
- }
- filein.close();
- ofstream fileout("a.txt");
- if (!fileout)
- {
- cout << "Nieudana proba otwarcia pliku!" << endl;
- system("pause");
- return 1;
- }
- for (int i = 0;i < ilosc;i++)
- {
- fileout << fixed<<setprecision(1)<<temp[i] << endl;
- }
- fileout.close();
- fileout.open("b.txt",ios::app);
- double suma = 0;
- for (int i = 0;i < ilosc;i++) suma += temp[i];
- double srednia = suma / ilosc;
- fileout << "srednia: " << fixed << setprecision(3) << srednia << endl;
- fileout.close();
- system("pause");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement