vertc

17-01

Jan 17th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. void rowkwadratowe() {
  8.     double a,b,c,delta,x0,x1,x2;
  9.     cout<<endl<<"Podaj liczbe a: ";
  10.     cin>>a;
  11.     cout<<"Podaj liczbe b: ";
  12.     cin>>b;
  13.     cout<<"Podaj liczbe c: ";
  14.     cin>>c;
  15.     cout<<endl<<"Wzor funkcji to: "<<a<<"x^2 + "<<b<<"x + "<<c<<"\n";
  16.     if(a==0) {
  17.         cout<<"Jest to rownanie liniowe.";
  18.     }
  19.     delta = b*b - 4*a*c;
  20.     cout<<"Delta wynosi: "<<delta<<"\n";
  21.     if(delta<0) {
  22.         cout<<"Brak rozwiazania.";
  23.     }
  24.     else {
  25.         if(delta==0) {
  26.             x0 = -1 * b / (2*a);
  27.             cout<<"Jedno rozwiazanie: x1/2 = "<<x0;
  28.         }
  29.     else {
  30.         x1 = (-1 * b - sqrt(delta)) / (2*a);
  31.         x2 = (-1 * b + sqrt(delta)) / (2*a);
  32.         cout<<"Dwa rozwiazania: x1 = "<<x1<<" i x2 = "<<x2;
  33.     }
  34.     }
  35. }
  36.  
  37. void euklides() {
  38.     int d,e;
  39.     cout<<endl<<"Podaj pierwsza liczbe: ";
  40.     cin>>d;
  41.     cout<<"Podaj druga liczbe: ";
  42.     cin>>e;
  43.     do {
  44.         if(d>e) d=d-e;
  45.         else e=e-d;
  46.     }
  47.     while(d!=e);
  48.     cout<<"Najwiekszy wspolny dzielnik to: "<<d<<endl;
  49. }
  50. int main() {
  51.     int wybor=0;
  52.     while(wybor!=3) {
  53.         cout<<endl<<"______________________________"<<endl;
  54.         cout<<"|1. Rownanie kwadratowe       |" <<endl;
  55.         cout<<"|2. Algorytm Euklidesa (NWD)  |" <<endl;
  56.         cout<<"|3. Wyjscie                   |" <<endl;
  57.         cout<<"|_____________________________|" <<endl;
  58.         cout<<endl<<"Wybierz dzialanie (1, 2 lub 3): ";
  59.         cin>>wybor;
  60.         switch(wybor)
  61.         {
  62.         case 1:
  63.             rowkwadratowe();
  64.             break;
  65.         case 2:
  66.             euklides();
  67.             break;
  68.         case 3:
  69.             cout<<endl<<"Wychodzenie z programu...";
  70.             break;
  71.         }
  72.     }
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment