Сделал 1 Задание со списками
This commit is contained in:
parent
5dbf4901b8
commit
632a718df1
71 changed files with 106 additions and 0 deletions
1
ProcessingSequences/46Ex/input.txt
Normal file
1
ProcessingSequences/46Ex/input.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
5 4 3 2 1
|
||||
22
ProcessingSequences/46Ex/main.c
Normal file
22
ProcessingSequences/46Ex/main.c
Normal 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);
|
||||
}
|
||||
11
ProcessingSequences/46Ex/makefile
Normal file
11
ProcessingSequences/46Ex/makefile
Normal 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
|
||||
20
ProcessingSequences/46Ex/solution_polynomial.c
Normal file
20
ProcessingSequences/46Ex/solution_polynomial.c
Normal 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", ¤t) != 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", ¤t) == 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
8
ProcessingSequences/46Ex/solution_polynomial.h
Normal file
8
ProcessingSequences/46Ex/solution_polynomial.h
Normal 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
|
||||
23
ProcessingSequences/46Ex/tools.c
Normal file
23
ProcessingSequences/46Ex/tools.c
Normal 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;
|
||||
}
|
||||
}
|
||||
8
ProcessingSequences/46Ex/tools.h
Normal file
8
ProcessingSequences/46Ex/tools.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef TOOLS
|
||||
#define TOOLS
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
FILE * getFile(void);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue