Сделал 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 4 3 2 1

View file

@ -0,0 +1,22 @@
#include <stdio.h>
#include "tools.h"
#include "solution_polynomial.h"
/*
Example: 5 4 3 2 1
x: 2
Answer: 80 + 32 + 12 + 4 + 1 = 129
160 + 48 + 12 + 2 = 222
*/
int main(void) {
double x, derivative, polynomial;
FILE * file = getFile();
if (file == NULL) return 1;
printf("Enter the x cordinate: ");
scanf("%lf", &x);
if (solutionPolynomial(file, x, &derivative, &polynomial)) return 1;
printf("The solution of the polynomial is %.0lf\nThe solution of the derivative is %.0lf", polynomial, derivative);
}

View file

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

View file

@ -0,0 +1,20 @@
#include "solution_polynomial.h"
int solutionPolynomial(FILE * file, double x, double * derivative, double * polynomial) {
double current;
if (fscanf(file, "%lf", &current) != 1) {
printf("File is empty!");
return 1;
}
*derivative = *polynomial = 0;
do {
*derivative = *derivative * x + *polynomial;
*polynomial = *polynomial * x + current;
// c4x^3 + c3x^2 + c2x + c = c = c2x + c = c3x^2 + c2x + c = ...
} while (fscanf(file, "%lf", &current) == 1);
return 0;
}

View file

@ -0,0 +1,8 @@
#ifndef SOLUTION_POLYNOMIAL
#define SOLUTION_POLYNOMIAL
#include <stdio.h>
int solutionPolynomial(FILE * file, double x, double * derivative, double * polynomial);
#endif // SOLUTION_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