Facebook
From Paltry Leech, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 255
  1. //max
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. float(float a, float b, float c)
  6. {
  7.         if (a>b)
  8.        
  9. }
  10.  
  11. //liniowamz
  12. #include <iostream>
  13.  
  14. using namespace std;
  15.  
  16. float mz(float a, float b)
  17. {
  18.         return (-b) / a;
  19. }
  20.  
  21. int main()
  22. {
  23.  
  24.         cout << "Podaj a: ";
  25.         static float a;
  26.         cin >> a;
  27.         cin.get();
  28.         cout << "Podaj b: ";
  29.         static float b;
  30.         cin >> b;
  31.         cin.get();
  32.        
  33.         float foo = mz(a, b);
  34.  
  35.         cout << "Miejsce zerowe funkcji f(x)=" << a << "x+(" << b << ") to punkt: (" << foo << ", 0)" << endl;
  36.        
  37.         cin.get();
  38.         return 0;
  39. }
  40.  
  41. //delta
  42. #include <iostream>
  43.  
  44. using namespace std;
  45.  
  46. struct mz
  47. {
  48.         double x1;
  49.         double x2;
  50.         bool no_solution = 0;
  51. };
  52.  
  53. mz obl_mz(double a, double b, double c)
  54. {
  55.         mz result{};
  56.  
  57.         double delta = ((b*b) - (4*a*c));
  58.  
  59.         if (delta < 0)
  60.         {
  61.                 result.no_solution = 1;
  62.         }
  63.         else if (delta > 0)
  64.         {
  65.                 result.x1 = ((-b) - sqrt(delta)) / (2 * a);
  66.                 result.x2 = ((-b) + sqrt(delta)) / (2 * a);
  67.         }
  68.         else
  69.         {
  70.                 result.x1 = result.x2 = (-b) / (2 * a);
  71.         }
  72.  
  73.         return result;
  74. }
  75.  
  76. int main()
  77. {
  78.  
  79.         cout << "OBLICZANIE MIEJSC ZEROWYCH FUNKCJI KWADRATOWEJ" << endl;
  80.         cout << "----------------------------------------------" << endl;
  81.  
  82.         cout << "Poda a: ";
  83.         double a;
  84.         cin >> a;
  85.         cin.get();
  86.         cout << "Poda b: ";
  87.         double b;
  88.         cin >> b;
  89.         cin.get();
  90.         cout << "Poda c: ";
  91.         double c;
  92.         cin >> c;
  93.         cin.get();
  94.  
  95.         mz wynik = obl_mz(a, b, c);
  96.         if (wynik.no_solution == 1)
  97.         {
  98.                 cout << "Brak miejsc zerowych w przestrzeni liczb rzeczywistych" << endl;
  99.         }
  100.         else if (abs(wynik.x1 - wynik.x2) < 0.000000000001)
  101.         {
  102.                 cout << "x=" << wynik.x1;
  103.         }
  104.         else
  105.         {
  106.                 cout << "x1=" << wynik.x1 << ", x2=" << wynik.x2 << endl;
  107.         }
  108.  
  109.         cin.get();
  110.         return 0;
  111. }
  112.  
  113. //fib
  114. #include <iostream>
  115.  
  116. using namespace std;
  117.  
  118. unsigned long fib_r(const unsigned int n)
  119. {
  120.         if (n < 1) return 0;
  121.         else if (n == 1 || n == 2) return 1;
  122.         else return (fib_r(n - 1) + fib_r(n - 2));
  123. }
  124.  
  125. int main()
  126. {
  127.         cout << "Ktory wyraz ciagu Fibonacciego obliczyc: ";
  128.         unsigned int n;
  129.         cin >> n;
  130.         cin.get();
  131.  
  132.         cout << "#" << n << " wyraz to: " << fib_r(n) << endl;
  133.         cin.get();
  134. }