/*
 * 16-polinomio.c
 *
 * Escriba un programa que permita calcular el valor del
 * siguiente polinomio para cualquier valor de x:
 *
 *     x^4 + 3 x^2 - 2 x + 1
 */

#include <stdio.h>

int
main(void)
{
	double x, y;

	printf("Ingrese el valor de x: ");
	scanf("%lf", &x);

	/* versión con llamadas a función pow(), muuy lentaaa */
	/* y= pow(x, 4.0) + 3 * pow(x, 2.0) - 2 * x + 1; */

	/* versión con aritmética flotante más rápida */
	/* y= x * x * x * x + 3 * x * x - 2 * x + 1; */

	/* versión más eficiente de cálculo */
	/* y= x x x x + 3 x x - 2 x + 1
	 * y= x (x x x + 3 x - 2) + 1
	 * y= x (x (x x + 3) - 2) + 1
	 */
	y= x * ( x * ( x * x + 3.0) - 2.0) + 1.0;

	printf("En x=%f el polinomio vale %f\n", x, y);

	return 0;
}
