/*  determine the roots of an equation using iteration  */
#include <stdio.h>
#include <math.h>

#define TRUE  1
#define FALSE 0

void main(void)
{
	int flag = TRUE, count = 0;
	float guess, root, test, error;

	/* read input parameters */
	printf("Initial guess: ");
	scanf("%f",&guess);
	while (flag)  {
		++count;
		if (count == 50 ) flag = FALSE;
		test = 10. - 3. * guess * guess;
		if (test > 0) {
			root = pow(test, 0.2);
			printf("\nIteration number: %2d", count);
			printf("  x= %7.5f", root);
			error = fabs(root - guess);
			if (error > 0.00001) guess = root;  /* repeat calculation   */
			else   {                            /* display final answer */
				flag = FALSE;                   /* error message        */
				printf("\n\nRoot= %7.5f", root);
				printf("  No. of iterations= %2d\n", count);
			}
		}
		else  {
			flag = FALSE;                      /* another error message */
			printf("\nNumbers out of range - try another initial guess");
		}
	}
	if ((count == 50) && (error > 0.00001))
		printf("\n\nConvergence not obtained after 50 iterations");
	getchar();
	getchar();
}


