Сделал 22 Задание

This commit is contained in:
AZEN-SGG 2024-09-25 08:00:08 +03:00
parent 973e407a45
commit 2e4417c1dc
7 changed files with 97 additions and 0 deletions

1
22Ex/input.txt Normal file
View file

@ -0,0 +1 @@
1 2 3 4 5

21
22Ex/main.c Normal file
View file

@ -0,0 +1,21 @@
#include <stdio.h>
#include "tools.h"
#include "make_increasing.h"
/*
23 Task
Example:
1 2 3 4 5 - possible
2 1 3 5 4 - impossible
*/
int main(void) {
FILE * file = getFile();
if (file == NULL) return 1;
if (makeIncreasing(file) != TRUE) {
printf("No, it is impossible");
return 1;
} else printf("Yes, it is possible");
return 0;
}

21
22Ex/make_increasing.c Normal file
View file

@ -0,0 +1,21 @@
#include "make_increasing.h"
int makeIncreasing(FILE * file) {
double current, next;
unsigned short used = 0;
if (fscanf(file, "%lf", &current) != 1) {
printf("File is empty!");
return 0;
}
while (fscanf(file, "%lf", &next) == 1) {
if ((next - current) < DISREG) {
if (used == TRUE) return 0;
used = TRUE;
}
current = next;
}
return 1;
}

12
22Ex/make_increasing.h Normal file
View file

@ -0,0 +1,12 @@
#ifndef MAKE_INCREASING
#define MAKE_INCREASING
#include <stdio.h>
#include <math.h>
#define DISREG 1.e-6
#define TRUE 1
int makeIncreasing(FILE * file);
#endif

11
22Ex/makefile Normal file
View file

@ -0,0 +1,11 @@
all: main.o make_increasing.o tools.o
gcc main.o make_increasing.o tools.o && del *.o
main.o: main.c
gcc -c main.c
make_increasing.o: make_increasing.c
gcc -c make_increasing.c
tools.o: tools.c
gcc -c tools.c

23
22Ex/tools.c Normal file
View file

@ -0,0 +1,23 @@
#include "tools.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
22Ex/tools.h Normal file
View file

@ -0,0 +1,8 @@
#ifndef TOOLS
#define TOOLS
#include <stdio.h>
FILE * getFile(void);
#endif