All pastes #242521 Raw Edit

Unnamed

public c v1 · immutable
·published 2006-11-07 10:42 UTC
rendered paste body
#include <stdio.h>#include <math.h>int main(void){    /*    folgende 6 Ergebniskategorien sind möglich:    1. Kategorie: a=0 -> lineare Gleichung mit einer Lösung    2. Kategorie: D=0, quadr. Gleichung mit einer (doppelten) Lösung    3. Kategorie: D<0, da Diskriminante negativ -> komplexe Lösung    4. Kategorie: D>0, quadr. Gleichung mit zwei Lösungen    5. Kategorie: a=b=c=0 -> triviale Lösung    6. Kategorie: a=b=0, c=x -> keine Lösung, da c ungleich 0    */        char berechnung='j';    float a,b,c,d,p,q,x1,x2;        while(berechnung!='n') {        printf("\nBerechnung a*x^2+b*x+c=0\n\n");        printf("Koeffizient a: ");        scanf("%f", &a);        fflush(stdin);        printf("Koeffizient b: ");        scanf("%f", &b);        fflush(stdin);        printf("Koeffizient c: ");        scanf("%f", &c);        fflush(stdin);        if(a==0) {                if(b==0 && c==0) { //5. Kategorie                    printf("\nTriviale L\224sung, da 0=0");                    }                if(b==0 && c!=0) { //6. Kategorie                    printf("\nKeine L\224sung, da c!=0 Widerspruch ergibt");                    }                if(b!=0 && c!=0) { //1. Kategorie                    printf("\nEs liegt lineare Gleichung vor -> eine L\224sung:\n");  // 1. Kategorie                    x1=-c/b;                    printf("x=%f", x1);                    }        }        else { //Umformung            p=b/a;            q=c/a;            d=(b*b)-(4*a*c); //Berechnung der Diskriminante                    if(d<0.0000001 && d>-0.0000001) { // 2. Kategorie | festlegen der Epsilonumgebung von 10^-7 und Test                x1=-b/(2*a);                printf("\nQuadratische Gleichung mit Diskriminante=0, eine (doppelte) L\224sung:");                printf("\nx=%f", x1);                }            if(d<0) { // 3. Kategorie                printf("\nQuadratische Gleich mit negativer Diskriminante:\nkonj. komplexe L\224sung");                printf("\nx1=%f + %fi", -p/2, sqrt(-((p*p)/4-q)));                printf("\nx1=%f - %fi", -p/2, sqrt(-((p*p)/4-q)));                              }            if(d>0) { //4. Kategorie                x1=-p/2 + sqrt((p*p)/4-q);                x2=-p/2 - sqrt((p*p)/4-q);                printf("\nQuadratische Gleichung mit zwei L\224sungen:");                printf("\nx1=%f", x1);                printf("\nx2=%f", x2);                }        }        printf("\n\nErneute Berechnung? j/n: ");        berechnung=getchar();        fflush(stdin);        }     exit(0);}