Сделал 2 Задание
This commit is contained in:
parent
d32450977c
commit
8e7bf70696
5 changed files with 50 additions and 16 deletions
BIN
Second/a.exe
Normal file
BIN
Second/a.exe
Normal file
Binary file not shown.
|
@ -1,18 +1,38 @@
|
||||||
#include "count_elements.h"
|
#include "count_elements.h"
|
||||||
|
|
||||||
int countElements(FILE * file) {
|
double detectNumber(double number, double count) {
|
||||||
int current, count;
|
if ((1 - number > INACCURACY) || (number - 5 > INACCURACY)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
for (double i = 1.; i < 6; i++) {
|
||||||
|
// printf("%lf ? \n", abs(number - i));
|
||||||
|
if (fabs(number - i) < INACCURACY) return (1 - (int)(fmod(count, pow(10., i)) / pow(10., i - 1))) * pow(10., i - 1);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
count = 0;
|
double summa(double info_count) {
|
||||||
|
int count = 0.;
|
||||||
|
|
||||||
if (fscanf(file, "%d", ¤t) != 1)
|
for (int i = 0; i < 5; i++) {
|
||||||
|
count += fmod(info_count, 10.);
|
||||||
|
info_count /= 10;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
double countElements(FILE * file) {
|
||||||
|
double current;
|
||||||
|
double count = 100000.;
|
||||||
|
|
||||||
|
if (fscanf(file, "%lf", ¤t) != 1)
|
||||||
{
|
{
|
||||||
printf("File is empty!\n");
|
printf("File is empty!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
if (current <= 5 && current >= 1) count++;
|
count += detectNumber(current, count);
|
||||||
} while (fscanf(file, "%d", ¤t) == 1);
|
} while (fscanf(file, "%lf", ¤t) == 1);
|
||||||
|
|
||||||
return count;
|
return summa(count);
|
||||||
}
|
}
|
|
@ -2,7 +2,12 @@
|
||||||
#define COUNT_ELEMENTS
|
#define COUNT_ELEMENTS
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
int countElements(FILE * file);
|
#define INACCURACY 1.e-10
|
||||||
|
|
||||||
|
double detectNumber(double number, double count);
|
||||||
|
double summa(double count);
|
||||||
|
double countElements(FILE * file);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,7 +1,16 @@
|
||||||
1
|
1.5
|
||||||
2
|
2
|
||||||
3
|
2.5
|
||||||
|
2
|
||||||
|
3.5
|
||||||
4
|
4
|
||||||
5
|
4.5
|
||||||
6
|
4
|
||||||
5
|
4
|
||||||
|
4
|
||||||
|
4
|
||||||
|
4
|
||||||
|
4
|
||||||
|
5.5
|
||||||
|
0.5
|
||||||
|
48
|
|
@ -7,6 +7,6 @@ int main(void) {
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
printf("Count of numbers between 1 to 5 is %d", countElements(file));
|
printf("Count of numbers between 1 to 5 is %lf", countElements(file));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue