Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <fstream>
- using namespace std;
- int main(){
- fstream f;
- fstream g;
- f.open("dane.txt");
- g.open("dane-zapis.txt");
- float a ,b ,c, x0, x1, x2;
- double delta;
- string liczby;
- getline(f, liczby);
- while(!f.eof()){
- cout << a << "x^2+" << b << "x+" << c << "=0\n";
- g << a << "x^2+" << b << "x+" << c << "=0\n";
- delta = b * b - 4 * a * c;
- cout << "delta=" << delta << endl;
- g << "delta=" << delta << endl;
- if (delta < 0) {
- cout << "Brak rozwiazan\n";
- g << "Brak rozwiazan\n";
- } else if (delta == 0) {
- x0 = (-b / (2 * a));
- cout << "pierwiastek to " << x0 << "\n";
- g << "pierwiastek to " << x0 << "\n";
- } else {
- x1 = (-b - sqrt(delta)) / (2 * a);
- x2 = (-b + sqrt(delta)) / (2 * a);
- cout << "pierwszy pierwiastek: " << x1 << "\ndrugi pierwiastek:" << x2;
- g << "pierwszy pierwiastek: " << x1 << "\ndrugi pierwiastek:" << x2;
- }
- }
- f.close();
- g.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement