Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. #include <limits>
  5. using namespace std;
  6.  
  7. double long func(double long a, double long b, double long c, double long x);
  8.  
  9. int main()
  10. {
  11.     setprecision(numeric_limits<long double> ::digits10 + 1);
  12.    
  13.     //MIEJSCA ZEROWE 3.2
  14.         long double a;
  15.         long double b;
  16.         long double c;
  17.         long double y1, y2;
  18.         cin >> a;
  19.         cin >> b;
  20.         cin >> c;
  21.  
  22.         long double x1 = (-b - sqrt(b*b - 4 * a * c)) / (2 * a);
  23.         long double x2 = (-b + sqrt(b*b - 4 * a * c)) / (2 * a);
  24.    
  25.         if(c == 0){
  26.             y1 = 0;
  27.             y2 = -(b/a);
  28.         } else if (b > abs(a * c)) {
  29.             y1 = (-b - sqrt(b*b - 4 * a * c)) / (2 * a);
  30.             y2 = c / (y1 * a);
  31.         } else {
  32.             y1 = (-b + sqrt(b*b - 4 * a * c)) / (2 * a);
  33.             y2 = c / (y1 * a);
  34.         }
  35.  
  36.         cout << "x1: " << setprecision(5) << x1 << endl;
  37.         cout << "x2: " << setprecision(5) << x2 << endl;
  38.         cout << "y1: " << setprecision(5) << y1 << endl;
  39.         cout << "y2: " << setprecision(5) << y2 << endl;
  40.  
  41.         cout << "Wartość w x1: " << func(a,b,c,x1) << endl;
  42.         cout << "Wartość w x2: " << func(a,b,c,x2) << endl;
  43.         cout << "Wartość w y1: " << func(a,b,c,y1) << endl;
  44.         cout << "Wartość w y2: " << func(a,b,c,y2) << endl;
  45. }
  46.  
  47. double long func(double long a, double long b, double long c, double long x){
  48.     return (a * (x * x) + (b * x) + c);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement