Added polynomial input interface
This commit is contained in:
parent
49619c27e0
commit
c83cc2894c
33
main.c
33
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<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);
|
||||
}
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user