fork download
  1. // 03-03-2014
  2. // JNRois12
  3.  
  4. #include <iostream>
  5. #include <cmath>
  6. using namespace std;
  7.  
  8. float CalculatePitagoras(float bValue, float cValue){
  9. float a, b, c;
  10. float a2, b2, c2;
  11.  
  12. b = bValue;
  13. c = cValue;
  14.  
  15. // operation
  16. b2 = b * b;
  17. c2 = c * c;
  18. a2 = b2 + c2;
  19. a = sqrt(a2);
  20.  
  21. cout << "a = " << a << " (sqrt of " << a2 << ") " << endl
  22. << "b = " << b << " (sqrt of " << b2 << ") " << endl
  23. << "c = " << c << " (sqrt of " << c2 << ") " << endl;
  24.  
  25. return 0;
  26. }
  27. float CalculateBhaskara(float aValue, float bValue, float cValue){
  28. float delta;
  29. float sqrtdt;
  30. float x1, x2;
  31. float a, b, c;
  32. float a2, b2, c2;
  33.  
  34. a = aValue;
  35. b = bValue;
  36. c = cValue;
  37.  
  38. //operation
  39. b2 = b * b;
  40. delta = b2 - 4 * a*c;
  41. sqrtdt = sqrt(delta);
  42. x1 = float(-b + sqrtdt) / float (2 * a);
  43. x2 = float(-b - sqrtdt) / float (2 * a);
  44.  
  45.  
  46. cout << "Delta = " << delta << endl
  47. << " x1 = " << x1 << endl
  48. << " x2 = " << x2 << endl
  49. << " a=" << a
  50. << " b=" << b
  51. << " c=" << c << endl;
  52.  
  53. return 0;
  54. }
  55.  
  56. int main() {
  57.  
  58. CalculatePitagoras(3, 4); // b, c
  59. cout << endl;
  60. CalculateBhaskara(1, -5, 6); // a, b, c
  61.  
  62. return 0;
  63. }
Success #stdin #stdout 0s 3300KB
stdin
Standard input is empty
stdout
a = 5 (sqrt of 25) 
b = 3 (sqrt of 9) 
c = 4 (sqrt of 16) 

Delta = 1
 x1 = 3
 x2 = 2
 a=1 b=-5 c=6