admin
|
|
« Odpowiedz #1 : Grudzieñ 08, 2010, 13:00:37 » |
|
Trójmian kwadratowy #include <cstdlib> #include <iostream> #include <math.h> using namespace std;
float delta(float d, float e,float f) {return e*e-4*d*f;} float pierw1 (float d,float e,float f, float g) {return (-e-sqrt(g))/(2*d);} float pierw2 (float d,float e,float f, float g) {return (-e+sqrt(g))/(2*d);} int main(int argc, char *argv[]) {float a,b,c; cout<<'\n'<<"podaj wartosc wspolczynnika a= "; cin>>a; cout<<'\n'<<"podaj wartosc wspolczynnika b= "; cin>>b; cout<<'\n'<<"podaj wartosc wspolczynnika c= "; cin>>c; if (delta(a,b,c)<0){cout<<'\n'<<"Brak pierwiastkow rownania";} else if (delta(a,b,c)==0) {cout<<endl<<"jeden pierwiastek rownania x1/x2= "<<-b/(2*a);} else {float d=delta(a,b,c); cout<<endl<<"x1= "<<pierw1(a,b,c,d); cout<<endl<<"x2= "<<pierw2(a,b,c,d);} cout<<endl; system("PAUSE"); return EXIT_SUCCESS; }
|