Quadratische Gleichungen in C

Hier ein total simples Programm, um eine Quadratische Gleichung mit p/q Formel zu lösen (im Softwareunterricht entstanden :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);
		}
	}
}

Kommentare

malo
malo am Donnerstag, 17. März 2005 um 16:34

Was jetzt noch intersant wäre, is was das nun alles geht?
Da ich noch nie C/++ oder sonstiges Auser PHP / MySQL zu tun hatte.

Das ist wohl eher nen Script als nen Tutorial, würde mich freuen wenn du das Editierst.

Stoke


(in Worten)