Advertisement
daniv1

Untitled

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