Added polynomial input interface

This commit is contained in:
Dmitriy Shishkov 2021-10-30 16:16:56 +03:00
parent 49619c27e0
commit c83cc2894c
No known key found for this signature in database
GPG Key ID: 14358F96FCDD8060
2 changed files with 40 additions and 3 deletions

33
main.c
View File

@ -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<x> (space) <y>\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);
}

View File

@ -1,12 +1,22 @@
#ifndef POLYNOMIAL_INTERPOLATION_H
#define POLYNOMIAL_INTERPOLATION_H
#include <stdio.h>
#include <stdlib.h>
/*
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