#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

double rnd(void)
{
	double	d;

	do {
		d = rand() - RAND_MAX / 2.0;
	} while (d == 0.0);
	return rand() / d;
}

void f(double a, double b, double c, double x)
{
	double	f;

	f = a * x * x + b * x + c;
	printf("x=%f f=%f\n", x, f);
}

int main()
{
	double	a, b, c, d, x1, x2;
	int	i;

	srand(time(NULL));
	for (i = 0; i < 10; i++) {
		while (1) {
			a = rnd();
			b = rnd();
			c = rnd();
			d = b * b - 4 * a * c;
			if (a != 0.0 && d >= 0.0) break;
		}
		x1 = (-b + sqrt(d)) / (2 * a);
		x2 = (-b - sqrt(d)) / (2 * a);
		printf("a=%f b=%f c=%f\n", a, b, c);
		f(a, b, c, x1);
		f(a, b, c, x2);
	}
	return 0;
}
