Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <stdlib.h>
- using namespace std;
- double sign(double s)
- {
- if(s > 0) return 1;
- if(s < 0) return -1;
- if(s ==0) return 0;
- }
- int main()
- {
- double a,b,c,delta,x1,x2;
- while(1){
- cout<<"Podaj a(1)"<<endl;
- cin>>a;
- cout<<"Podaj b(-5)"<<endl;
- cin>>b;
- cout<<"Podaj c(6)"<<endl;
- cin>>c;
- delta=(pow(b,2)) - (4*a*c);
- if(delta < 0 || a==0)
- {
- cout<<"Brak miejsc zerowych lub a=0"<<endl;
- }
- else{break;}
- }
- x1= (-b - sqrt(delta))/2*a;
- x2= (-b + sqrt(delta))/2*a;
- cout<<"Pierwiastki sposobiem pierwszym:"<<endl;
- cout<<"x1="<<x1<<endl;
- cout<<"x2="<<x2<<endl;
- double z= ((-b)/(2*a));
- cout<<z<<endl;
- double znak=sign(z);
- cout<<znak<<endl;
- x1 =( z + (znak * sqrt((pow(z,2))- (c/a))));
- x2 = c /(a*x1);
- cout<<"Pierwiastki sposobiem drugim:"<<endl;
- cout<<"x1="<<x1<<endl;
- cout<<"x2="<<x2<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement