Доделал Задание 10

This commit is contained in:
AZEN-SGG 2024-09-27 09:30:00 +03:00
parent 51dd1e537a
commit 5dbf4901b8
7 changed files with 58 additions and 49 deletions

30
10Ex/count_between.c Normal file
View file

@ -0,0 +1,30 @@
#include "count_between.h"
double fmax(double a, double b) {
if ((a - b) > eps) return a;
return b;
}
double fmin(double a, double b) {
if ((a - b) > eps) return b;
return a;
}
int countBetween(FILE * file) {
double first, second, current;
int count = 0;
if ((fscanf(file, "%lf", &first) != 1) || (fscanf(file, "%lf", &second) != 1)) {
printf("There is NO 2 variables\n");
return 1;
}
current = fmax(first, second);
second = fmin(first, second);
first = current;
while (fscanf(file, "%lf", &current) == 1) {
if (((current - second) > eps) && ((first - current) > eps)) count++;
}
return count;
}

12
10Ex/count_between.h Normal file
View file

@ -0,0 +1,12 @@
#ifndef COUNT_BETWEEN
#define COUNT_BETWEEN
#include <stdio.h>
#define eps 1.e-6
double fmax(double a, double b);
double fmin(double a, double b);
int countBetween(FILE * file);
#endif // COUNT_BETWEEN

1
10Ex/input.txt Normal file
View file

@ -0,0 +1 @@
1 5 2 3 4 1.1 10 5.5 0.5 0 -1 -2

View file

@ -1,38 +1,8 @@
#include <stdio.h>
#include "tools.h"
#include "count_between.h"
#define eps = 1.e-10
double fmax(double a, double b) {
if ((a - b) > eps) return a;
return b;
}
double fmin(double a, double b) {
if ((a - b) > eps) return b;
return a;
}
int countBetween(FILE * file);
int countBetween(FILE * file) {
double first, second, current;
int count = 0;
if ((fscanf(file, "%lf", &first) != 1) || (fscanf(file, "%lf", &second) != 1) {
printf("There is NO 2 variables\n");
return 1
}
current = fmax(first, second);
second = fmin(first, second);
first = current;
while (fscanf(file, "%lf" &current) == 1) {
if (((current - second) > eps) && ((first - current) < eps)) count++;
}
return count;
}
// 10Ex
int main(void) {
FILE * file = getFile();

11
10Ex/makefile Normal file
View file

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

View file

@ -12,7 +12,7 @@ double detectNumber(double number, double count) {
}
double summa(double info_count) {
int count = 0.;
int count = 0;
for (int i = 0; i < 5; i++) {
count += fmod(info_count, 10.);

View file

@ -1,16 +1 @@
1.5
2
2.5
2
3.5
4
4.5
4
4
4
4
4
4
5.5
0.5
48
0.123 -1.12 1 2 1 2 1 2 3.4 5