#include <stdio.h>

#define N	20
#define PI	3.14159265359
#define E	2.7182818284590452354

double factorial(int n) {
	int i;
	double f;

	for(f=1,i=2; i<=n;i++) {
		f *= i;
	}
	return f;
}

double potencia(float b, int e) {
	int i;
	double p;

	for(p=1,i=1; i<=e;i++) {
		p *= b;
	}
	return p;
}

double e_elevat_x(int x) {
	int i; double sum;

	for(sum=0,i=0;i<=N;i++) {
		sum += potencia(x,i)/factorial(i);
	}
	return sum;
}

double cos(double x) {
	int i; double sum;
	for(sum=0,i=0;i<=N;i++) {
		sum += potencia(x,2*i)/factorial(2*i)*
			potencia(-1,i);
	}
	return sum;
}

double sin(double x) {
	int i; double sum;
	for(sum=0,i=0;i<=N;i++) {
		sum += potencia(x,2*i+1)/
			factorial(2*i+1)*
			potencia(-1,i);
	}
	return sum;
}

main() {
	int x=10;
	printf("e^%d = (aprox) %lf\n", x, e_elevat_x(x));
	printf("e^%d = %lf\n", x, potencia(E, x));
	printf("sin(PI) = %lf\n", sin(PI));
	printf("cos(PI) = %lf\n", cos(PI));
}

