zadasd_zest2/asdzes2zad4wartosce/main.c
2019-01-24 20:27:57 +01:00

46 lines
845 B
C

/* Zad 4 z zestawu 2. Ćwiczenia z ASD.
* Oblicza liczbę e,
* wypisując na wyjściu kolejne wyrazy szeregu w kolejnych iteracjach.
* Przyjmuje na wejściu docelową dokładność
* 24 sty 2019
* Michał Krzysztof Feiler (s444368) <archiet@wmi.amu.edu.pl>
* */
#include <math.h>
#include <stdio.h>
static long double eps;
static long long unsigned silnia;
static long double x;
static long long unsigned n;
int next()
{
/* long double p = x; */
n++;
silnia *= n;
long double inv_silnia = ((long double)1) / silnia;
x += inv_silnia;
/* return fabsl(x - p) >= eps; */
return inv_silnia >= eps;
}
void print()
{
printf("x_%llu=%Lf, ", n, x);
}
int main()
{
scanf("%Lf", &eps);
x = 1;
n = 0;
silnia = 1;
print();
while (next())
print();
print();
return 0;
}