Initialization#
This commit is contained in:
parent
2af7bc6708
commit
dc81195d36
14
a1/program.c
14
a1/program.c
@ -2,7 +2,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
|
||||
int main() {
|
||||
char line[100];
|
||||
@ -29,11 +28,10 @@ int main() {
|
||||
}
|
||||
|
||||
// Parse the line
|
||||
double temp_expected_result;
|
||||
sscanf(line, "%lf%c%lf=%lf", &num1, &op, &num2, &temp_expected_result);
|
||||
|
||||
// Round the expected result to two decimal places
|
||||
expected_result = round(temp_expected_result * 100) / 100.0;
|
||||
if (sscanf(line, "%lf%c%lf=%lf", &num1, &op, &num2, &expected_result) != 4) {
|
||||
printf("CHYBA\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if the input is valid
|
||||
if (op != '+' && op != '-' && op != '*' && op != '/') {
|
||||
@ -64,11 +62,9 @@ int main() {
|
||||
}
|
||||
|
||||
// Check if the result is correct
|
||||
if (result == expected_result) {
|
||||
if (((int)(result * 100 + 0.5) / 100.0) == expected_result) {
|
||||
printf("OK\n");
|
||||
} else {
|
||||
printf("%lf", expected_result);
|
||||
printf("%lf", temp_expected_result);
|
||||
printf("ZLE\n");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user