feat: Initial commit
This commit is contained in:
71
Laboratorio 3/esercizio3.c
Normal file
71
Laboratorio 3/esercizio3.c
Normal file
@@ -0,0 +1,71 @@
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
#define INPUT_FILE "./numeri.txt"
|
||||
|
||||
int max(int a, int b)
|
||||
{
|
||||
if (a > b) {
|
||||
return a;
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
int min(int a, int b)
|
||||
{
|
||||
if (a < b) {
|
||||
return a;
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
FILE *fp_read;
|
||||
|
||||
fp_read = fopen(INPUT_FILE, "r");
|
||||
|
||||
if (fp_read == NULL)
|
||||
{
|
||||
printf("Error opening file\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int x, y, a;
|
||||
int maxVal, minVal, scartati = 0;
|
||||
|
||||
if (fscanf(fp_read, " %d", &x) == EOF || fscanf(fp_read, " %d",& y) == EOF) {
|
||||
fclose(fp_read);
|
||||
return 1; // Terminate if there are only two numbers
|
||||
}
|
||||
|
||||
minVal = min(x, y);
|
||||
maxVal = max(x, y);
|
||||
|
||||
while (!feof(fp_read))
|
||||
{
|
||||
if (fscanf(fp_read, " %d", &a) == EOF) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (x + y != a && x - y != a && x * y != a && (y==0 || x / y != a )) {
|
||||
scartati++;
|
||||
continue;
|
||||
}
|
||||
|
||||
minVal = min(minVal, a);
|
||||
maxVal = max(maxVal, a);
|
||||
|
||||
x = y;
|
||||
y = a;
|
||||
}
|
||||
|
||||
printf("Numero massimo: %d\nNumero minimo: %d\nNumeri scartati: %d\n", maxVal, minVal, scartati);
|
||||
|
||||
fclose(fp_read);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user