Wieso fuktioniert das Programm nicht?
-
{#include <stdio.h> #include <math.h> double fplus(int n); double fminus(int n); int main(void) { for (int i = 0; i <= 20; ++i) { printf("y (n = %2d) = %10.4f\n", i, fplus(i) - fminus(i)); } } double fplus(int n) { double y = 1/sqrt(5.0); for(int i = 1; i <= n + 1; ++i) { y *= (1 + sqrt(5.0))/2; } return y; } double fminus(int n) { double y = 1/sqrt(5.0); for(int i = 1; i <= n + 1; ++i) { y *= (1 - sqrt(5.0))/2; } return y; } }
ich weiß nicht wie ich das ganze in so einen tag einpacke sry.. ich versteh net warum das net läuft der compiler evtl ?
-
Ganz am Ende eine schließende Klammer zu viel.
So klappts schon:
#include <stdio.h> #include <math.h> double fplus(int n); double fminus(int n); int main(void) { for (int i = 0; i <= 20; ++i) { printf("y (n = %2d) = %10.4f\n", i, fplus(i) - fminus(i)); } } double fplus(int n) { double y = 1/sqrt(5.0); for(int i = 1; i <= n + 1; ++i) { y *= (1 + sqrt(5.0))/2; } return y; } double fminus(int n) { double y = 1/sqrt(5.0); for(int i = 1; i <= n + 1; ++i) { y *= (1 - sqrt(5.0))/2; } return y; }
Mit pow kannste Dir sogar zwei Schleifen sparen.
#include <stdio.h> #include <math.h> double fplus(int n); double fminus(int n); int main(void) { for (int i = 0; i <= 20; ++i) { printf("y (n = %2d) = %10.4f\n", i, fplus(i) - fminus(i)); } } double fplus(int n) { double y = 1/sqrt(5.0) * pow((1 + sqrt(5.0))/2,n+1); return y; } double fminus(int n) { double y = 1/sqrt(5.0) * pow((1 - sqrt(5.0))/2,n+1); return y; }
-
rival schrieb:
ich weiß nicht wie ich das ganze in so einen tag einpacke sry..
Code markieren (mit der Maus) und auf den C-Button unter dem
klicken.