You are on page 1of 2

#include <iostream>

#include <cmath>
using namespace std;
int main()
{
int odabir;
cout <<"-------------------------MENI ------------------------------"<<
endl;
cout << endl;
cout <<"Odaberite zeljenu funkciju programa unosom broja !"<< endl;
cout << endl;
cout <<"Funkcije:"<< endl;
cout <<"1 - Kvadratna jednadzba"<< endl;
cout <<"2 - Dvije jednadzbe s dvije nepoznanice"<< endl;
cout << endl;
cout << "Funkcija --> ";
cin >> odabir;
switch (odabir)
{
case 1:
double a, b, c, d, x1, x2, x;
int i, n;
cout << endl;
cout << "Broj izracuna kvadratne jednadzbe --> ";
cin >> n;
cout <<endl;
cout <<"Oblik kvadratne jednadzbe: aX^2 + bX + c = 0"<<endl;
for (i=1; i<=n; ++i)
{ cout <<endl;
cout << "Broj a --> ";
cin >> a;
cout << "Broj b --> ";
cin >> b;
cout << "Broj c --> ";
cin >>c;
d = pow(b,2)-4*a*c;
if (a != 0){
if (d > 0)
{x1 = (-b + sqrt(d))/(2*a);
x2 = (-b - sqrt(d))/(2*a);
cout <<endl;
cout << "X1= "<< x1 <<endl;
cout << "X2= "<< x2 <<endl;}
else if (d == 0)
{x = -b/2*a;
cout <<endl;
cout <<"X1=X2= "<< x <<endl;}
else
{x1 = -b/(2*a);
x2 = sqrt(abs(d))/(2*a);
cout <<endl;
cout << "X1= "<< x1 << "+" << x2 << " i"<<endl;
cout << "X2= "<< x1 << "-" << x2 << " i"<<endl;}
}
else{
cout <<endl;
cout <<"Jednadzba je linearna: bX + c = 0"<<endl;
c = c*(-1);
x = c/b;
cout <<endl;
cout <<"X= "<<x<<endl;}
}
cout <<endl;
cout << "Za kraj rada programa potvrdite unos bilo kojeg znaka ! ";
char z;
cin >> z;
break;
case 2:
double a1, b1, c1, d1, e1, f1, x3, y, g, n1;
cout << endl;
cout <<"Prva jednadzba: aX + bY = c"<<endl;
cout <<"Druga jednadzba: dX + eY = f"<<endl;
cout <<endl;
cout <<"Koeficjent a --> ";
cin >> a1;
cout <<"Koeficjent b --> ";
cin >> b1;
cout <<"Koeficjent c --> ";
cin >> c1;
cout <<"Koeficjent d --> ";
cin >> d1;
out <<"Koeficjent e --> ";
cin >> e1;
cout <<"Koeficjent f --> ";
cin >> f1;
g = ((a1*f1)-(c1*d1));
n1 = ((a1*e1)-(b1*d1));
if (n1 != 0 && a1 != 0)
{y=g/n1;
x3=(c1-(b1*y))/a1;
cout << endl;
cout <<"X= "<<x3<<endl;
cout <<"Y= "<<y<<endl;}
else
{cout <<"Nema rjesenja !"<<endl;}
char z1;
cout << endl;
cout <<"Za kraj rada programa potvrdite unos bilo kojeg znaka !";
cin >>z1;
break;
}
return 0;
}

You might also like