T
Danke erstmal für deine Antwort.
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <ctype.h>
void main (void)
{
float rn, n, r, q, q1, p;
int i;
i = 1.0;
printf ("\n\t Z i n s s a t z\n");
printf ("\t _______________\n\n\n\n");
printf ("\t Geben Sie bitte folgende Variablen an:\n\n\n");
printf ("\t Rentenendwert in Euro: \t"); scanf ("%f", &rn);
printf ("\t Rate in Euro: \t\t\t"); scanf ("%f", &r);
printf ("\t Laufzeit in Jahren: \t\t"); scanf ("%f", &n);
{
q = 1.001;
while(q < 1000000)
{
if ((pow(q,n) - ((rn / r) * q) + (rn / r - 1)) > 0)
break;
q += 0.001;
}
}
do
{
q1 = ((((n - 1.0) * pow(q,n)) + 1.0) - rn / r) / ((n * pow(q,n - 1.0)) - (rn / r));
}
while (fabs(q1 - q) > 0.1);
i++;
p = (q1-1.0)*100.0;
printf ("\n\n\t Iterationsschritte: \t\t\t%d", i);
printf ("\n\t Der Zinssatz betraegt: \t"); printf ("%10.2f", p); printf (" Prozent");
}
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <ctype.h>
void main (void)
{
float rn, n, r, q, q1, p;
int i;
i = 1.0;
printf ("\n\t Z i n s s a t z\n");
printf ("\t _______________\n\n\n\n");
printf ("\t Geben Sie bitte folgende Variablen an:\n\n\n");
printf ("\t Rentenendwert in Euro: \t"); scanf ("%f", &rn);
printf ("\t Rate in Euro: \t\t\t"); scanf ("%f", &r);
printf ("\t Laufzeit in Jahren: \t\t"); scanf ("%f", &n);
{
q = 1.001;
do
{
if ((pow(q,n) - ((rn / r) * q) + (rn / r - 1)) > 0)
break;
q += 0.001;
} while(q < 1000000);
}
do
{
q1 = ((((n - 1.0) * pow(q,n)) + 1.0) - rn / r) / ((n * pow(q,n - 1.0)) - (rn / r));
}
while (fabs(q1 - q) > 0.1);
i++;
p = (q1-1.0)*100.0;
printf ("\n\n\t Iterationsschritte: \t\t\t%d", i);
printf ("\n\t Der Zinssatz betraegt: \t"); printf ("%10.2f", p); printf (" Prozent");
}
Das ist nun einmal die while-Schleife und einmal die do-while nach deiner Vorgabe. Funktioniert einwandfrei;). Kannst du mir evtl. sagen, an welcher Stelle ich da den Zähler setzen müsste, um die Iterationsschritte zu zählen? So wie ich den bisher integriert habe, zählt er zwei Iterationschritte, was aber mathematisch gesehen bei dem regula falsi Verfahren nicht korrekt sein kann.
Zum Deltavergleich: Ich bin absoluter Anfänger und kann damit jetzt auf Schlag nciht viel anfangen. Wie ersetze ich meine 1000000 denn durch einen Deltavergleich?
Gruß