Monday, 12 January 2015

[C] Programm gibt Wert nicht aus? topx







Hallo zusammen, ich habe das Problem, dass beim Ausführen meines Codes nicht die Scheitelhöhe angezeigt wird. Ist da was im printf falsch? oder an meinem Code? Die main war vorgegeben, damit sollte es eigentlich funktionieren :(

Bild der cmd http://abload.de/image.php?img=tst6jpu44.jpg







int scheitelhoehe (struct parabel p, double *y) {
int rc = 0;

if ((p.a)==0) {
return rc = 1;
}
else {
*y = p.c - ((p.b*p.b) / (4*p.a));
rc = 0;
}
}


void sort_parabeln (struct parabel *p, int n) {

int i, j;
double yh1, xh2;
struct parabel cache;

for(i = 0; i < n-1; i++) {
if (scheitelhoehe(p[i], &yh1) == 0) {
cache = p[i];
p[i] = p[n-1];
p[n-1] = cache;

n = n - 1;
i = i - 1;
}
}

for (i = 0; i < n -1; ++i) {
for (j = 0; j < n - i - 1; ++j) {
scheitelhoehe(p[j], &yh1);
scheitelhoehe(p[j + 1], &xh2);

if (yh1 > xh2) {
cache = p[j];
p[j] = p[j + 1];
p[j + 1] = cache;
}
}
}
}

int main ( ) {

struct parabel p [] = {

{1 ,2 ,3},
{2 ,5 ,-19},
{0 ,0 ,0},
{-1 ,0 ,0}
};

double y;

printf ("Index 1 ist eine echte Parabel:");
printf ("scheitelhoehe %d\n", (p[0], &y ) == 0);
sort_parabeln (p, sizeof (p) / sizeof (struct parabel));
return 0;}











No comments:

Post a Comment