#include <stdio.h>
#include <math.h>
int main() {
    int a;
    double w1, w2;
    void abcFormule(int, int, int, int*, double*, double*);
    /* 2x² - 3x - 2 */
    abcFormule(2, -3, -2, &a, &w1, &w2);
    printf("De formule 2x*x - 3x - 2 heeft ");
    switch (a) {
        case 0: 
            printf("geen wortels.\n"); 
            break;
        case 1:
            printf("een wortel x=%6.2lf.\n", w1); 
            break;
        case 2:
            printf("twee wortels x=%6.2lf en x=%6.2lf.\n", w1, w2); 
            break;
    }
    getchar();
    return 0;
}
void abcFormule(int a, int b, int c, int* aantalWortels, double* wortel1, double* wortel2) {
    if (a==0) {
        /* beetje flauw: het is een lineare functie */
        if (b==0) {
            /* erg flauw: het is een constante functie */
            *aantalWortels=0;
        }
        else {
            *aantalWortels=1;
            *wortel1=c/b;
        }
    }
    else {
        double determinant=b*b-4*a*c;
        if (determinant<0) {
            /* kwadratische functie zonder wortels: */
            *aantalWortels=0;
        }
        else {
            if (determinant==0) {
                /* kwadratische functie met 1 wortel: */
                *aantalWortels=1;
                *wortel1=-b/(2*a);
            }
            else {
                /* kwadratische functie met 2 wortels: */
                *aantalWortels=2;
                *wortel1=(-b-sqrt(determinant))/(2*a);
                *wortel2=(-b+sqrt(determinant))/(2*a);
            }
        }
    }
}
    
