Advertisement
Kocyk

numerki delta

Oct 11th, 2019
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. using namespace std;
  5. double sign(double s)
  6. {
  7.     if(s > 0) return 1;
  8.     if(s < 0) return -1;
  9.     if(s ==0) return 0;
  10. }
  11. int main()
  12. {
  13.     double a,b,c,delta,x1,x2;
  14.     while(1){
  15.     cout<<"Podaj a(1)"<<endl;
  16.     cin>>a;
  17.     cout<<"Podaj b(-5)"<<endl;
  18.     cin>>b;
  19.     cout<<"Podaj c(6)"<<endl;
  20.     cin>>c;
  21.     delta=(pow(b,2)) - (4*a*c);
  22.     if(delta < 0 || a==0)
  23.     {
  24.         cout<<"Brak miejsc zerowych lub a=0"<<endl;
  25.  
  26.     }
  27.     else{break;}
  28.     }
  29.     x1= (-b - sqrt(delta))/2*a;
  30.     x2= (-b + sqrt(delta))/2*a;
  31.     cout<<"Pierwiastki sposobiem pierwszym:"<<endl;
  32.     cout<<"x1="<<x1<<endl;
  33.     cout<<"x2="<<x2<<endl;
  34.     double z= ((-b)/(2*a));
  35.     cout<<z<<endl;
  36.     double znak=sign(z);
  37.     cout<<znak<<endl;
  38.     x1 =( z + (znak * sqrt((pow(z,2))- (c/a))));
  39.     x2 = c /(a*x1);
  40.  
  41.     cout<<"Pierwiastki sposobiem drugim:"<<endl;
  42.     cout<<"x1="<<x1<<endl;
  43.     cout<<"x2="<<x2<<endl;
  44.  
  45.  
  46.     return 0;
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement