Сделал, но не проверил 10е Задание, TODO: Закончить его
This commit is contained in:
parent
a9a13014bf
commit
51dd1e537a
1 changed files with 41 additions and 0 deletions
41
10Ex/main.c
41
10Ex/main.c
|
@ -1 +1,42 @@
|
|||
#include <stdio.h>
|
||||
#include "tools.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" ¤t) == 1) {
|
||||
if (((current - second) > eps) && ((first - current) < eps)) count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
FILE * file = getFile();
|
||||
if (file == NULL) return 1;
|
||||
|
||||
printf("Count of number between first and second is %d", countBetween(file));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue