Сделал 36 задание
This commit is contained in:
parent
c9160d0358
commit
3dd2710fc1
8 changed files with 99 additions and 0 deletions
BIN
Fourth/a.exe
Normal file
BIN
Fourth/a.exe
Normal file
Binary file not shown.
23
Fourth/get_file.c
Normal file
23
Fourth/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
Fourth/get_file.h
Normal file
8
Fourth/get_file.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef GET_FILE
|
||||
#define GET_FILE
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
FILE * getFile(void);
|
||||
|
||||
#endif
|
||||
7
Fourth/input.txt
Normal file
7
Fourth/input.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
11
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
10
|
||||
17
Fourth/main.c
Normal file
17
Fourth/main.c
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include <stdio.h>
|
||||
#include "get_file.h"
|
||||
#include "max_difference.h"
|
||||
|
||||
/*
|
||||
36 Çàäà÷à
|
||||
*/
|
||||
|
||||
int max(int first, int second);
|
||||
int maxDifference(FILE * file);
|
||||
|
||||
int main(void) {
|
||||
FILE * file = getFile();
|
||||
if (file == NULL) return -1;
|
||||
printf("Maximum difference between elements is %d", maxDifference(file));
|
||||
return 0;
|
||||
}
|
||||
11
Fourth/makefile
Normal file
11
Fourth/makefile
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
all: main.o max_difference.o get_file.o
|
||||
gcc main.o max_difference.o get_file.o && del *.o
|
||||
|
||||
main.o: main.c
|
||||
gcc -c main.c
|
||||
|
||||
max_difference.o: max_difference.c
|
||||
gcc -c max_difference.c
|
||||
|
||||
get_file.o: get_file.c
|
||||
gcc -c get_file.c
|
||||
23
Fourth/max_difference.c
Normal file
23
Fourth/max_difference.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#include "max_difference.h"
|
||||
|
||||
int max(int first, int second) {
|
||||
if (first > second) return first;
|
||||
return second;
|
||||
}
|
||||
|
||||
int maxDifference(FILE * file) {
|
||||
int current, last, maxim;
|
||||
if (fscanf(file, "%d", ¤t) != 1) {
|
||||
printf("File is empty!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
last = current;
|
||||
maxim = 0;
|
||||
|
||||
while (fscanf(file, "%d", ¤t) == 1) {
|
||||
maxim = max(maxim, abs(last - current));
|
||||
last = current;
|
||||
}
|
||||
return maxim;
|
||||
}
|
||||
10
Fourth/max_difference.h
Normal file
10
Fourth/max_difference.h
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef MAX_DIFFERENCE
|
||||
#define MAX_DIFFERENCE
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int max(int first, int second);
|
||||
int maxDifference(FILE * file);
|
||||
|
||||
#endif // MAX_DIFFERENCE
|
||||
Loading…
Add table
Add a link
Reference in a new issue