Untitled
unknown
plain_text
21 days ago
511 B
5
Indexable
Fixed Point iteration
#include <stdio.h>
#include <math.h>
float g(float x) {
return pow(x + 1, 1.0/3.0);
}
int main() {
float x0, x1, error;
int i = 1;
printf("Enter initial guess: ");
scanf("%f", &x0);
printf("Enter tolerable error: ");
scanf("%f", &error);
}
do {
x1 = g(x0);
printf("Iteration %d: x = %f\n", i, x1);
if (fabs(x1 - x0) < error)
break;
x0 = x1;
i++;
} while (1);
printf("\nApproximate root = %f\n", x1);
return 0;
}
}
}Editor is loading...
Leave a Comment