Advertisement
daniv1

Untitled

Nov 26th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include<cmath>
  4.  
  5. int main()
  6. {
  7.     float a, b, c, x1, x2, D, eps = 0.001;
  8.     std::cout << "VVedit koeficientu" << "\n";
  9.     std::cin >> a >> b >> c;
  10.  
  11.     if (a == 0 && b == 0 && c == 0) {
  12.         std::cout << "rivnanja pogano obymovlene" << "\n";
  13.         system("pause");
  14.         exit;
  15.     }
  16.     else if (a == 0 && b != 0 && c != 0) {
  17.         float x;
  18.         //bx+c=0
  19.         //x=-c/b
  20.         x = -c / b;
  21.         std::cout << "x= " << x << "\n";
  22.         system("pause");
  23.         exit;
  24.     }
  25.     else if (a == 0 && b == 0 && c != 0) {
  26.         std::cout << "Rivnanja ne mae rozvjazkiv" << "\n";
  27.         system("pause");
  28.         exit;
  29.     }
  30.     else {
  31.         D = b*b - 4 * a*c;
  32.         if (D < 0) {
  33.             std::cout << "rivnaja ne maje rozvjazkiv" << "\n";
  34.             system("pause");
  35.         }
  36.         else if (abs(D) < eps) {
  37.             float x;
  38.             x = (-b / (2 * a));
  39.             std::cout << "x = " << x << "\n";
  40.         }
  41.         else
  42.         {
  43.             x1 = (-b + sqrt(D)) / (2 * a);
  44.             x2 = (-b - sqrt(D)) / (2 * a);
  45.             std::cout << "x1=" << x1 << "\n" << "x2=" << x2 << "\n";
  46.             system("pause");
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement