Сделал 1 Задание со списками

This commit is contained in:
AZEN-SGG 2024-10-04 10:43:43 +03:00
parent 5dbf4901b8
commit 632a718df1
71 changed files with 106 additions and 0 deletions

View file

@ -0,0 +1,5 @@
1
2
3
4
5

View file

@ -0,0 +1,23 @@
#include <stdio.h>
#include "tools.h"
#include "solve_polynomial.h"
/*
Problem 45
Coordinate X: 2
Solution: 129
Derivative: 222
*/
int main(void) {
double derivative, polynomial, x;
FILE * file = getFile();
if (file == NULL) return 1;
printf("Enter x coordinat: ");
scanf("%lf", &x);
if (solvePolynomial(file, x, &derivative, &polynomial)) return 1;
printf("Solve of the polynomial is %lf\nSolve of its derivative is %lf\n", polynomial, derivative);
return 0;
}

View file

@ -0,0 +1,11 @@
all: main.o solve_polynomial.o tools.o
gcc main.o solve_polynomial.o tools.o && del *.o
main.o: main.c
gcc -c main.c
solve_polynomial.o: solve_polynomial.c
gcc -c solve_polynomial.c
tools.o: tools.c
gcc -c tools.c

View file

@ -0,0 +1,20 @@
#include "solve_polynomial.h"
int solvePolynomial(FILE * file, double x, double * derivative, double * polynomial) {
double current, i;
if (fscanf(file, "%lf", &current) != 1) {
printf("File is empty!\n");
return 1;
}
*derivative = *polynomial = i = 0.;
do {
*polynomial += current * pow(x, i);
*derivative += i * current * pow(x, i - 1);
i++;
} while (fscanf(file, "%lf", &current) == 1);
return 0;
}

View file

@ -0,0 +1,9 @@
#ifndef SOLVE_POLYNOMIAL
#define SOLVE_POLYNOMIAL
#include <stdio.h>
#include <math.h>
int solvePolynomial(FILE * file, double x, double * derivative, double * polynomial);
#endif // SOLVE_POLYNOMIAL

View file

@ -0,0 +1,23 @@
#include "tools.h"
FILE * getFile(void)
{
FILE * file;
char filename[50];
printf("Enter filename: ");
if (scanf("%s", filename) == 1)
{
file = fopen(filename, "r");
if (file == NULL) {
printf("Error file!\n");
return NULL;
} else {
return file;
}
} else
{
printf("Empty name!\n");
return NULL;
}
}

View file

@ -0,0 +1,8 @@
#ifndef TOOLS
#define TOOLS
#include <stdio.h>
FILE * getFile(void);
#endif