| functions/eq-sec-degree-starting-point.c - Et program der finder rødder i en andengradsligning - uden funktioner - alt i main. | Lektion 5 - slide 5 : 30 Program 1 |
#include <stdio.h>
#include <math.h>
int main(void) {
int i = 3;
double a, b, c, discriminant;
/* ... */
/* Solve three equations: */
for (i = 1; i <= 3; i++){
printf("Enter coeficients a, b, and c: ");
scanf("%lf %lf %lf", &a, &b, &c);
discriminant = b * b - 4 * a * c;
if (discriminant < 0)
printf("No roots\n");
else if (discriminant == 0)
printf("One root: %f\n", -b/(2*a));
else
printf("Two roots: %f and %f\n",
(-b + sqrt(discriminant))/(2*a),
(-b - sqrt(discriminant))/(2*a) );
}
/* ... */
return 0;
}