Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio.h"
- #include "math.h"
- float calculateX(float xFrom, float i, float step) {
- return xFrom + i*step;
- }
- float yFormula(float x) {
- return exp(-(x - 2) * (x - 2));
- }
- void printLBase(int i, int n, float xFrom, float step) {
- printf("(");
- for (int j = 0; j <= n; j++) {
- if (j == i)
- continue;
- printf("(x - %f)", calculateX(xFrom, j, step));
- }
- printf(")/(");
- for (int j = 0; j <= n; j++) {
- if (j == i)
- continue;
- printf("(%f - %f)", calculateX(xFrom, i, step), calculateX(xFrom, j, step));
- }
- printf(")");
- }
- int main(int argc, char** argv) {
- float xFrom = 2;
- float xTo = 4;
- float step = 0.2;
- int n = (int)((xTo-xFrom) / step);
- printf("L(x) = ");
- for (int i = 0; i <= n; i++) {
- printLBase(i, n, xFrom, step);
- if (i < n)
- printf(" + ");
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment