Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <cmath>
- using namespace std;
- void rowkwadratowe() {
- double a,b,c,delta,x0,x1,x2;
- cout<<endl<<"Podaj liczbe a: ";
- cin>>a;
- cout<<"Podaj liczbe b: ";
- cin>>b;
- cout<<"Podaj liczbe c: ";
- cin>>c;
- cout<<endl<<"Wzor funkcji to: "<<a<<"x^2 + "<<b<<"x + "<<c<<"\n";
- if(a==0) {
- cout<<"Jest to rownanie liniowe.";
- }
- delta = b*b - 4*a*c;
- cout<<"Delta wynosi: "<<delta<<"\n";
- if(delta<0) {
- cout<<"Brak rozwiazania.";
- }
- else {
- if(delta==0) {
- x0 = -1 * b / (2*a);
- cout<<"Jedno rozwiazanie: x1/2 = "<<x0;
- }
- else {
- x1 = (-1 * b - sqrt(delta)) / (2*a);
- x2 = (-1 * b + sqrt(delta)) / (2*a);
- cout<<"Dwa rozwiazania: x1 = "<<x1<<" i x2 = "<<x2;
- }
- }
- }
- void euklides() {
- int d,e;
- cout<<endl<<"Podaj pierwsza liczbe: ";
- cin>>d;
- cout<<"Podaj druga liczbe: ";
- cin>>e;
- do {
- if(d>e) d=d-e;
- else e=e-d;
- }
- while(d!=e);
- cout<<"Najwiekszy wspolny dzielnik to: "<<d<<endl;
- }
- int main() {
- int wybor=0;
- while(wybor!=3) {
- cout<<endl<<"______________________________"<<endl;
- cout<<"|1. Rownanie kwadratowe |" <<endl;
- cout<<"|2. Algorytm Euklidesa (NWD) |" <<endl;
- cout<<"|3. Wyjscie |" <<endl;
- cout<<"|_____________________________|" <<endl;
- cout<<endl<<"Wybierz dzialanie (1, 2 lub 3): ";
- cin>>wybor;
- switch(wybor)
- {
- case 1:
- rowkwadratowe();
- break;
- case 2:
- euklides();
- break;
- case 3:
- cout<<endl<<"Wychodzenie z programu...";
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment