diff --git a/main.c b/main.c index 5634325..d92ea80 100644 --- a/main.c +++ b/main.c @@ -37,10 +37,37 @@ void print_newton_poly(double *f, double *x, int n) } } +unsigned int insert_n() +{ + printf("Insert number of dots: "); + unsigned int n = 0; + scanf("%u", &n); + + return n; +} + +void insert_coords(double *xes, double *yes, unsigned int n) +{ + printf("Insert dots coordinates in the following format:\n (space) \nEach dot on new line\n"); + + for (int i = 0; i < n; i++) + { + double x, y; + scanf("%lf %lf", &x, &y); + + xes[i] = x; + yes[i] = y; + } +} + int main() { - double x[] = {0, 1, 2, 3}, - y[] = {-2, -5, 0, -4}; + unsigned n = insert_n(); - print_newton_poly(div_diff_es(x, y, 4), x, 4); + double *x = (double *)malloc(sizeof(double) * n), + *y = (double *)malloc(sizeof(double) * n); + + insert_coords(x, y, n); + + print_newton_poly(div_diff_es(x, y, n), x, n); } \ No newline at end of file diff --git a/polynominal_interpolation.h b/polynominal_interpolation.h index 729d043..4ec01bd 100644 --- a/polynominal_interpolation.h +++ b/polynominal_interpolation.h @@ -1,12 +1,22 @@ #ifndef POLYNOMIAL_INTERPOLATION_H #define POLYNOMIAL_INTERPOLATION_H +#include +#include + /* Business logic */ double div_diff(double *y, double *x, int i, int d); double *div_diff_es(double *x, double *y, int n); + +/* + User interface +*/ + +unsigned int insert_n(); void print_newton_poly(double *f, double *x, int n); +void insert_coords(double *x, double *y, unsigned int n); #endif \ No newline at end of file