Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- #include<fstream>
- using namespace std;
- int main(int argc, char** argv){
- ifstream f;
- f.open("plik1.txt");
- while(!f.eof()){
- int a,b,c;
- float x1,x2;
- cout<<"Rownanie kwadratowe" <<endl;
- f>>a;
- cout<<"wspoczynnik a: " <<a<<endl;
- f>>b;
- cout<<"wspoczynnik b: "<<b<<endl;
- f>>c;
- cout<<"wspoczynnik c: "<<c<<endl;
- float delta=b*b-(4*a*c);
- if(delta<0){
- cout<<"Brak rozwiazan rownania"<<endl;
- }else if(delta == 0){
- x1 = -b/(2*a);
- cout<<"Jendo rozwiazanie rownania: "<<x1<<endl;
- }else if(delta >0){
- x1 = -b + sqrt(delta)/(2*a);
- x2 = -b - sqrt(delta)/(2*a);
- cout<<"Dwa rozwiazania: "<<endl;
- cout<<x1<<endl;
- cout<<x2<<endl;
- }
- f.close();
- ofstream f1("plik2.txt");
- //f1.open("plik2.txt");
- f1<< x1 << x2 <<endl;
- f1.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement