Advertisement
Mentosan

The Equation of Degree 2

May 17th, 2018
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "stdlib.h"
  3. #include <iostream>
  4. #include <math.h>
  5.  
  6. using namespace std;
  7. #define COEFICIENTI 3
  8.  
  9. void Culoare_Consola();
  10. float Delta_Ecuatie(float v[]);
  11.  
  12. float v[COEFICIENTI], delta, x1, x2;
  13.  
  14. int main() {
  15.  
  16.     char repeta;
  17.  
  18.     Culoare_Consola();
  19.     do {
  20.         cout << endl;
  21.         cout << " Introduceti coeficientii: " << endl;
  22.  
  23.         for (int i = 1; i <= COEFICIENTI; i++) {
  24.             if (i == 1) {
  25.                 cout << "a="; cin >> v[i];
  26.             }
  27.             else if (i == 2) {
  28.                 cout << "b="; cin >> v[i];
  29.             }
  30.             else if (i == 3) {
  31.                 cout << "c="; cin >> v[i];
  32.             }
  33.         }
  34.  
  35.         delta = Delta_Ecuatie(v);
  36.         cout << endl;
  37.  
  38.         if (delta < 0) {
  39.             cout << " (!)(!) Ecuatia nu are radacini reale! \n";
  40.         }
  41.         else if (delta == 0) {
  42.             cout << " (!) X1 = X2:  \n";
  43.             x1 = -v[2] / 2 * v[1];
  44.             x1 = x2;
  45.             cout << " x1 = x2 = " << x1 << endl;
  46.         }
  47.         else if (delta > 0) {
  48.             cout << " (!) Ecuatia are doua solutii reale! \n";
  49.             x1 = (-v[2] + sqrt(delta)) / 2 * v[1];
  50.             x2 = (-v[2] - sqrt(delta)) / 2 * v[1];
  51.             cout << " x1 = " << x1 << ", x2 = " << x2 << endl;
  52.         }
  53.         cout << " Mai vrei odata? (D/N)  "; cin >> repeta;
  54.     } while (repeta == 'D' || repeta == 'd');
  55.  
  56.     system("pause");
  57.     return 0;
  58. }
  59.  
  60. float Delta_Ecuatie(float v[]) {
  61.     float delta;
  62.    
  63.     delta = v[2] * v[2] - 4 * v[1] * v[3];
  64.  
  65.     return delta;
  66. }
  67.  
  68. void Culoare_Consola() {
  69.     system("COLOR 03");
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement