Pasta: 6444c1d4ab3783774a24921f98cc4cdf397f2495 (2017-11-21)

Język: C/C++
Adres: p43.pl/p,6444c1d4ab3783774a24921f98cc4cdf397f2495
Ilość linii: 89
Rozmiar: 1.47 kB
Wyświetleń: 238
Ostatnio użyto: 2018-10-21 09:27:23
#include "stdafx.h" #include "iostream" #include "conio.h" #include "math.h" using namespace std; int pierw_wsk(double a, double b, double c, double *x1, double *x2) { double d; d = (b * b) - 4 * a*c; if (d < 0) { return 0; } if (d == 0) { *x1 = (-b) / (2 * a); return 1; } *x1 = (-b - sqrt(d)) / (2 * a); *x2 = (-b + sqrt(d)) / (2 * a); return 2; } int pierw_ref(double a, double b, double c, double &x1, double &x2) { double d; d = (b * b) - 4 * a*c; if (d < 0) { return 0; } if (d == 0) { x1 = (-b) / (2 * a); return 1; } x1 = (-b - sqrt(d)) / (2 * a); x2 = (-b + sqrt(d)) / (2 * a); return 2; } int main() { double a, b, c, x1, x2; cout << "a: "; cin >> a; cout << "b: "; cin >> b; cout << "c: "; cin >> c; ///////////////////////////////// cout << "\n\nfunkcja przez wskaznik:\n"; switch (pierw_wsk(a, b, c, &x1, &x2)) { case 0: cout << "brak pierwiastkow"; break; case 1: cout << "x = " << x1; break; case 2: cout << "x1 = " << x1 << "\nx2 = " << x2; break; default: cout << "nie dziala"; break; } //////////////////////////////////// cout << "\n\nfunkcja przez referencje:\n"; switch (pierw_ref(a, b, c, x1, x2)) { case 0: cout << "brak pierwiastkow"; break; case 1: cout << "x = " << x1; break; case 2: cout << "x1 = " << x1 << "\nx2 = " << x2; break; default: cout << "nie dziala"; break; } _getch(); return 0; }