Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @file UE6_Uebung4.c
- * @brief File contains the main program
- * @author Felix Fischbach
- * @date 18.11.2014
- */
- #include <stdio.h>
- #include <conio.h>
- #include <math.h>
- int main(void);
- /**
- * @fn int main(void)
- * @brief Caculates x for 0=x^2+bx+c
- * @return "0" for no errors
- * @author Felix Fischbach
- * @date 18.11.2014
- *
- * Solves an equation 0 = x² + bx + c
- */
- int main(void)
- {
- double dB, dC; //Variables for input
- double dDiscr; //Variable for the discriminat
- double dPHalfSq; //Variable for (p/2)^2
- double dX1, dX2; //Variables for the solutions
- printf("---------------------\n");
- printf("| 0 = x^2 + b*x + c |\n");
- printf("---------------------\n\n");
- printf("Bitte einen Wert fuer b eingeben: ");
- scanf_s("%lf", &dB);
- fflush(stdin);
- printf("Bitte einen Wert fuer c eingeben: ");
- scanf_s("%lf", &dC);
- fflush(stdin);
- dPHalfSq = ((dB / 2) * (dB / 2));
- dDiscr = dPHalfSq - dC;
- if (dDiscr < 0)
- {
- printf("\nDie Rechnung mit Ihren Werten ergibt kein Ergebnis in den reellen Zahlen,\nda unter der Wurzel eine negative Zahl steht.");
- }
- else
- {
- if (dDiscr == 0)
- {
- dX1 = -(dB/2);
- printf("\nEs gibt nur eine Loesung:\nx = %lf", dX1);
- }
- else
- {
- dX1 = (-(dB / 2)) + sqrt(dDiscr);
- dX2 = (-(dB / 2)) - sqrt(dDiscr);
- printf("\nEs gibt zwei Loesungen:\nx1 = %lf\nx2 = %lf", dX1, dX2);
- }
- }
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement