Hier ien total simples Programm , was eine Quadratische Gleichung mit p/q Formel berechnet ( im softwareunterricht entsanden :D )

#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>

int quaGL(float,float,float,float,float *,float *);

main ()
{
float a, b, c, d;
float x1, x2;

printf ("Bitte geben Sie a ein: ";);
scanf ("%i",&a);
printf ("Bitte geben Sie b ein: ";);
scanf ("%i",&b);
printf ("Bitte geben Sie c ein: ";);
scanf ("%i",&c);
printf ("Bitte geben Sie d ein: ";);
scanf ("%i",&d);

if (a==0)
{
printf ("Diese Rechnung ist nicht moeglich , da eine Division durch Null erforderlich ist !";);
}
else
{
switch(quaGL(a, b, c, d, &x1, &x2))
{

case (1):
printf ("
Ergebnis x1 : %f
Ergebnis x2 : %f", x1,x2);
break;
case (2):
printf ("
Ergebnis : x1 = %f",x1);
break;
case (3):
printf ("
Ihre Rechnung ergibt keine Loesung !";);
break;
}
}
getch();
}

int quaGL (float a, float b, float c, float d, float * X1, float * X2)
{
float p,q,D;
p=b/a;
q=(c-d)/a;
D=(p/2)*(q/2)-q;
if (D>0)
{
* X1=-p/2+sqrt(D);
* X2=-p/2-sqrt(D);
return(1);
}
else
{
if(D==0)
{
* X1=-p/2;
return(2);
}
else
{
return(3);
}
}
}
Veröffentlicht on Monday 14. March 2005 at 20:38
Tags: