[ create a new paste ] login | about

Link: http://codepad.org/UULjIyHi    [ raw code | fork ]

C++, pasted on Oct 26:
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <clocale>


double *fact;
double *deg;

void degris(double x, int p)
{
	deg = new double[p];
	deg[0] = 1;
	deg[1] = x;
	int i;
	for(i=2; i<p; i++)
		deg[i] = deg[i-1]*x;
}
void fact_l(int n)
{
	fact = new double[n];
	fact[0] = 1;
	int i;
	for(i=1;i<n; i++)
		fact[i] = fact[i-1] * (double)i;
}
int main()
{
	setlocale(LC_CTYPE,"Russian");

	double delta = 1, m_exp, sum_exp=0, x;
    int n = 0;
	printf("Введите число от которого будите вычислять exp(x)\n");
	printf("x = ");
	scanf("%Lf",&x);
	m_exp = exp(x);
	while(delta != 0){
		n=1;
		printf("Точтность  1.e-%d \n",n);
		 /*Посчитаем все степени до заданного порядка*/
		degris(x,n);
		/*Факториалы*/
		fact_l(n);

		printf("%.*Lf \n",n,m_exp);

		for(int i = n-1; i >= 0; i--)
			sum_exp += deg[i]/fact[i];

	    printf("%.*Lf \n",n,sum_exp);
		delta = fabs(m_exp-sum_exp);
	    printf("Погрешность = %.*Lf \n",n,delta);
		n++;
		delete[] deg;
		delete[] fact;
	}
	system("pause");
}


Create a new paste based on this one


Comments: