Сделал 1 Задание со списками
This commit is contained in:
parent
5dbf4901b8
commit
632a718df1
71 changed files with 106 additions and 0 deletions
38
ProcessingSequences/Second/count_elements.c
Normal file
38
ProcessingSequences/Second/count_elements.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
#include "count_elements.h"
|
||||
|
||||
double detectNumber(double number, double 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;
|
||||
}
|
||||
|
||||
double summa(double info_count) {
|
||||
int count = 0;
|
||||
|
||||
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");
|
||||
return -1;
|
||||
}
|
||||
do {
|
||||
count += detectNumber(current, count);
|
||||
} while (fscanf(file, "%lf", ¤t) == 1);
|
||||
|
||||
return summa(count);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue