Facebook
From pdrewic, 3 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 122
  1. #include "pch.h" // nie wiem czy to potrzebne
  2. #include <iostream>
  3. #include <math.h>
  4. using namespace std;
  5.  
  6. int deltaFunction(int a, int b, int c) {
  7.  
  8.         int result;
  9.         result = b * b - 4 * a*c;
  10.         return result;
  11. }
  12.  
  13. void squaresFunction(int b, int delta, int a) {
  14.         // (-b -square(delta))/2a
  15.  
  16.         int x1=0,x2 = 0;
  17.         x1 = (-b - sqrt(delta)) / 2 * a;
  18.         x2 = (-b + sqrt(delta)) / 2 * a;
  19.  
  20.         cout << "x1=" << x1 << "x2=" << x2 << endl;
  21. }
  22.  
  23. void funkcjazero() {
  24.         cout << "0" << endl;
  25. }
  26.  
  27. int main()
  28. {
  29.         int a = 0, b = 0, c = 0, delta=0;
  30.         cout << "Wprowadz a = ";
  31.         cin >> a;
  32.  
  33.         cout << "Wprowadz b = ";
  34.         cin >> b;
  35.  
  36.         cout << "Wprowadz c = ";
  37.         cin >> c;
  38.  
  39.         delta = deltaFunction(a, b, c);
  40.         cout << "wynik = " << delta << endl;
  41.         if (delta > 0) {
  42.                 squaresFunction(b,delta,a);
  43.         }
  44.         else if (delta == 0) {
  45.                 funkcjazero();
  46.         }
  47.        
  48.  
  49.         system("pause");
  50. }
  51.