Сделал 1 Задание со списками
This commit is contained in:
parent
5dbf4901b8
commit
632a718df1
71 changed files with 106 additions and 0 deletions
23
ProcessingSequences/Fifth/get_file.c
Normal file
23
ProcessingSequences/Fifth/get_file.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#include "get_file.h"
|
||||
|
||||
FILE * getFile(void)
|
||||
{
|
||||
FILE * file;
|
||||
char filename[50];
|
||||
|
||||
printf("Enter filename: ");
|
||||
if (scanf("%s", filename) == 1)
|
||||
{
|
||||
file = fopen(filename, "r");
|
||||
if (file == NULL) {
|
||||
printf("Error file!\n");
|
||||
return NULL;
|
||||
} else {
|
||||
return file;
|
||||
}
|
||||
} else
|
||||
{
|
||||
printf("Empty name!\n");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
8
ProcessingSequences/Fifth/get_file.h
Normal file
8
ProcessingSequences/Fifth/get_file.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef GET_FILE
|
||||
#define GET_FILE
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
FILE * getFile(void);
|
||||
|
||||
#endif
|
||||
5
ProcessingSequences/Fifth/input.txt
Normal file
5
ProcessingSequences/Fifth/input.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
14
ProcessingSequences/Fifth/main.c
Normal file
14
ProcessingSequences/Fifth/main.c
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#include <stdio.h>
|
||||
#include "get_file.h"
|
||||
#include "max_deviation.h"
|
||||
|
||||
/*
|
||||
Çàäàíèå 37
|
||||
*/
|
||||
|
||||
int main(void) {
|
||||
FILE * file = getFile();
|
||||
if (file == NULL) return -1;
|
||||
printf("The standard deviation from the arithmetic mean is equal to %d", maxDeviation(file));
|
||||
return 0;
|
||||
}
|
||||
11
ProcessingSequences/Fifth/makefile
Normal file
11
ProcessingSequences/Fifth/makefile
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
all: main.o max_deviation.o get_file.o
|
||||
gcc main.o max_deviation.o get_file.o && del *.o
|
||||
|
||||
main.o: main.c
|
||||
gcc -c main.c
|
||||
|
||||
max_deviation.o: max_deviation.c
|
||||
gcc -c max_deviation.c
|
||||
|
||||
get_file.o: get_file.c
|
||||
gcc -c get_file.c
|
||||
26
ProcessingSequences/Fifth/max_deviation.c
Normal file
26
ProcessingSequences/Fifth/max_deviation.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#include "max_deviation.h"
|
||||
|
||||
int ipow(int number, int power) {
|
||||
int result = 1;
|
||||
for (int i = 0; i < power; i++) result *= number;
|
||||
return result;
|
||||
}
|
||||
|
||||
int maxDeviation(FILE * file) {
|
||||
int current, sq_sum, sum, count, ar_mean;
|
||||
if (fscanf(file, "%d", ¤t) != 1) {
|
||||
printf("File is empty!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
sq_sum = sum = count = 0;
|
||||
|
||||
do {
|
||||
sum += current;
|
||||
sq_sum += ipow(current, 2);
|
||||
count++;
|
||||
} while (fscanf(file, "%d", ¤t) == 1);
|
||||
|
||||
ar_mean = sum / count;
|
||||
return ((sq_sum - (sum * ar_mean * 2)) / count) + ipow(ar_mean, 2);
|
||||
}
|
||||
9
ProcessingSequences/Fifth/max_deviation.h
Normal file
9
ProcessingSequences/Fifth/max_deviation.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef MAX_DEVIATION
|
||||
#define MAX_DEVIATION
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int ipow(int number, int power);
|
||||
int maxDeviation(FILE * file);
|
||||
|
||||
#endif // MAX_DEVIATION
|
||||
Loading…
Add table
Add a link
Reference in a new issue