feat: Initial commit
This commit is contained in:
43
Laboratorio 1/calcolatrice.c
Normal file
43
Laboratorio 1/calcolatrice.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user