Доделал Задание 10
This commit is contained in:
parent
51dd1e537a
commit
5dbf4901b8
7 changed files with 58 additions and 49 deletions
30
10Ex/count_between.c
Normal file
30
10Ex/count_between.c
Normal 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", ¤t) == 1) {
|
||||||
|
if (((current - second) > eps) && ((first - current) > eps)) count++;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
12
10Ex/count_between.h
Normal file
12
10Ex/count_between.h
Normal 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
1
10Ex/input.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
1 5 2 3 4 1.1 10 5.5 0.5 0 -1 -2
|
||||||
34
10Ex/main.c
34
10Ex/main.c
|
|
@ -1,38 +1,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
|
#include "count_between.h"
|
||||||
|
|
||||||
#define eps = 1.e-10
|
// 10Ex
|
||||||
|
|
||||||
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" ¤t) == 1) {
|
|
||||||
if (((current - second) > eps) && ((first - current) < eps)) count++;
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
FILE * file = getFile();
|
FILE * file = getFile();
|
||||||
|
|
|
||||||
11
10Ex/makefile
Normal file
11
10Ex/makefile
Normal 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
|
||||||
|
|
@ -12,7 +12,7 @@ double detectNumber(double number, double count) {
|
||||||
}
|
}
|
||||||
|
|
||||||
double summa(double info_count) {
|
double summa(double info_count) {
|
||||||
int count = 0.;
|
int count = 0;
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
count += fmod(info_count, 10.);
|
count += fmod(info_count, 10.);
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1 @@
|
||||||
1.5
|
0.123 -1.12 1 2 1 2 1 2 3.4 5
|
||||||
2
|
|
||||||
2.5
|
|
||||||
2
|
|
||||||
3.5
|
|
||||||
4
|
|
||||||
4.5
|
|
||||||
4
|
|
||||||
4
|
|
||||||
4
|
|
||||||
4
|
|
||||||
4
|
|
||||||
4
|
|
||||||
5.5
|
|
||||||
0.5
|
|
||||||
48
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue