Advertisement
Guest User

Untitled

a guest
Oct 10th, 2015
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <math.h>
  4.  
  5.  
  6. float kwadrat(float x, float y, float z, float &k, float &l)
  7. {
  8. float delta;
  9.  
  10. delta = pow(y,2) - 4 *x*z;
  11. if (delta<0)
  12. return 1;
  13.  
  14. if (delta == 0)
  15. {
  16. k = (-y)/(2*x);
  17. l = (-y)/(2*x);
  18. return 2;
  19. }
  20. if (delta>0)
  21. {
  22. k = (-y-sqrt(delta))/(2*x);
  23. l = (-y+sqrt(delta))/(2*x);
  24. return 3;
  25. }
  26. }
  27.  
  28. float a, b, c, x1, x2;
  29. float& ref1;
  30. float& ref2;
  31. int d;
  32.  
  33. int main()
  34. {
  35. using namespace std;
  36.  
  37. ref1=x2;
  38. ref2=x2;
  39.  
  40. cout << "Podaj wspolczynniki przy odpowiednich potęgach" << endl;
  41. cout << "a= ";
  42. cin >> a;
  43. if (a == 0)
  44. cout << "To nie jest funkcja kwadratowa."; << endl;
  45.  
  46.  
  47. if (a!=0)
  48. {
  49. cout << "b= ";
  50. cin >> b;
  51. cout << "c= ";
  52. cin >> c;
  53. d= kwadrat(a, b, c, ref1, ref2);
  54. }
  55. if (d == 1)
  56.  
  57. cout << "Brak rozwiazan";
  58.  
  59. if (d == 2)
  60.  
  61. cout << "x=" << x1;
  62.  
  63. if (d == 3)
  64.  
  65. cout << "x1=" << x1 << "x2=" << x2;
  66.  
  67. system("pause");
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement