feat: Initial commit

This commit is contained in:
2024-03-22 17:14:57 +01:00
parent dc83234df1
commit db9bafe755
45 changed files with 1996 additions and 0 deletions

43
Laboratorio 1/EsempioIO.c Normal file
View File

@@ -0,0 +1,43 @@
#include <stdio.h>
int main()
{
FILE *fp_read, *fp_write;
char file_char, choice;
if ((fp_read = fopen("../Guide.txt", "r")) == NULL)
{
printf("Error opening file\n");
return 1;
}
if ((fp_write = fopen("../Output.txt", "w")) == NULL)
{
printf("Error opening file\n");
return 2;
}
printf("Print on console (C) or on file (F):");
choice = getchar();
while (!feof(fp_read))
{
file_char = fgetc(fp_read);
if (!feof(fp_read))
{
switch (choice)
{
case 'C':
printf("\nChar printed on the console: %c",
file_char);
break;
case 'F':
fputc(file_char, fp_write);
printf("\nChar saved on file: ");
putchar(file_char);
break;
default:
printf("Wrong choice\n");
return 3;
}
}
}
fclose(fp_read);
fclose(fp_write);
return 0;
}

View File

@@ -0,0 +1,4 @@
+ 15.225 30.51
- 42.1 10.01
* 0.62 2.4
/ 5.0 2.5

View File

@@ -0,0 +1,4 @@
+ 45.74
- 32.09
* 1.49
/ 2.00

View File

@@ -0,0 +1,12 @@
#include <stdio.h>
int main(void)
{
int x, y;
float z;
printf("Insert an integer number:");
scanf("%d", &x);
y = 3;
z = (float)(x) / y;
printf("%d/%d=%.3f\n", x, y, z);
return 0;
}

View File

@@ -0,0 +1,40 @@
#include <stdio.h>
#define P 3.14
int main()
{
char fig;
char dato;
float area;
float num;
scanf("%c %c%f", &fig, &dato, &num);
if (fig == 'Q')
{
if (dato == 'D')
{
area = num * num / 2;
}
else if (dato == 'L')
{
area = num * num;
}
printf("Area quadrato = %f\n", area);
}
else if (fig == 'C')
{
if (dato == 'D')
{
area = P * num * num / 4;
}
else if (dato == 'R')
{
area = P * num * num;
}
printf("Area cerchio = %f\n", area);
}
return 0;
}

View File

@@ -0,0 +1,43 @@
#include <stdio.h>
int main()
{
char operation;
float op1, op2, res;
operation = getchar();
if (scanf("%f %f", &op1, &op2) != 2) {
printf("Error: Invalid input\n");
return 2;
}
switch (operation)
{
case '+':
res = op1 + op2;
break;
case '-':
res = op1 - op2;
break;
case '*':
res = op1 * op2;
break;
case '/':
if (op2 == 0) {
printf("Error: divide by zero\n");
return 2;
}
res = op1 / op2;
break;
default:
printf("Error: invalid operation\n");
return 1;
}
printf("%c %f\n", operation, res);
return 0;
}

View File

@@ -0,0 +1,61 @@
#include <stdio.h>
int main()
{
FILE *fp_read, *fp_write;
char operation;
float op1, op2, res;
if ((fp_read = fopen("./Operations.txt", "r")) == NULL)
{
printf("Error opening file\n");
return 1;
}
if ((fp_write = fopen("./Results.txt", "w")) == NULL)
{
printf("Error opening file\n");
return 2;
}
while (!feof(fp_read))
{
fscanf(fp_read, " %c %f %f", &operation, &op1, &op2);
if (!feof(fp_read))
{
switch (operation)
{
case '+':
res = op1 + op2;
break;
case '-':
res = op1 - op2;
break;
case '*':
res = op1 * op2;
break;
case '/':
if (op2 == 0)
{
printf("Error: divide by zero\n");
return 3;
}
res = op1 / op2;
break;
default:
printf("Error: invalid operation\n");
return 1;
}
fprintf(fp_write, "%c %.2f\n", operation, res);
}
}
fclose(fp_read);
fclose(fp_write);
return 0;
}