Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. /**
  2. * @file UE6_Uebung4.c
  3. * @brief File contains the main program
  4. * @author Felix Fischbach
  5. * @date 18.11.2014
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <conio.h>
  10. #include <math.h>
  11.  
  12. int main(void);
  13.  
  14. /**
  15. * @fn int main(void)
  16. * @brief Caculates x for 0=x^2+bx+c
  17. * @return "0" for no errors
  18. * @author Felix Fischbach
  19. * @date 18.11.2014
  20. *
  21. * Solves an equation 0 = x² + bx + c
  22. */
  23. int main(void)
  24. {
  25. double dB, dC; //Variables for input
  26. double dDiscr; //Variable for the discriminat
  27. double dPHalfSq; //Variable for (p/2)^2
  28. double dX1, dX2; //Variables for the solutions
  29.  
  30.  
  31. printf("---------------------\n");
  32. printf("| 0 = x^2 + b*x + c |\n");
  33. printf("---------------------\n\n");
  34.  
  35. printf("Bitte einen Wert fuer b eingeben: ");
  36. scanf_s("%lf", &dB);
  37. fflush(stdin);
  38.  
  39. printf("Bitte einen Wert fuer c eingeben: ");
  40. scanf_s("%lf", &dC);
  41. fflush(stdin);
  42.  
  43. dPHalfSq = ((dB / 2) * (dB / 2));
  44.  
  45. dDiscr = dPHalfSq - dC;
  46.  
  47. if (dDiscr < 0)
  48. {
  49. printf("\nDie Rechnung mit Ihren Werten ergibt kein Ergebnis in den reellen Zahlen,\nda unter der Wurzel eine negative Zahl steht.");
  50. }
  51. else
  52. {
  53. if (dDiscr == 0)
  54. {
  55. dX1 = -(dB/2);
  56. printf("\nEs gibt nur eine Loesung:\nx = %lf", dX1);
  57. }
  58. else
  59. {
  60. dX1 = (-(dB / 2)) + sqrt(dDiscr);
  61. dX2 = (-(dB / 2)) - sqrt(dDiscr);
  62. printf("\nEs gibt zwei Loesungen:\nx1 = %lf\nx2 = %lf", dX1, dX2);
  63. }
  64. }
  65.  
  66. _getch();
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement