pvjc22/du4/program.c

54 lines
1012 B
C
Raw Normal View History

2022-03-30 20:03:13 +00:00
#include <stdio.h>
#include <stdbool.h>
2022-03-30 21:36:37 +00:00
int main(){
int c[2];
int a, i = 0;
int vysledok;
2022-03-30 21:36:37 +00:00
char riadok[999];
char *endptr = NULL;
bool first = true;
bool second = false;
2022-03-30 20:03:13 +00:00
while(1){
a++;
2022-03-30 21:36:37 +00:00
char* r = fgets(riadok,999,stdin);
if(*r == '\n'){
2022-03-30 21:36:37 +00:00
break;
}else if(*r == ' ')
2022-03-30 21:36:37 +00:00
continue;
else if(*r == '+'){
first = true;
second = true;;
2022-03-30 21:36:37 +00:00
continue;
}else if(*r == '-'){
first = false;
second = false;
2022-03-30 21:36:37 +00:00
continue;
}else if(*r == '/'){
first = true;
second = false;
2022-03-30 21:36:37 +00:00
continue;
}else if(*r == '*'){
first = false;
second = true;
2022-03-30 21:36:37 +00:00
continue;
2022-03-30 20:03:13 +00:00
}else{
2022-03-30 21:36:37 +00:00
float v = strtod(riadok,&endptr);
c[i++] = v;
continue;
2022-03-30 20:03:13 +00:00
}
}
if(first == true && second == true)
vysledok = c[0] + c[1];
else if(first == false && second == false)
vysledok = c[0] - c[1];
else if(first == true && second == false)
vysledok = c[0] / c[1];
else if(first == false && second == true)
vysledok = c[0] * c[1];
2022-03-30 21:36:37 +00:00
if(vysledok == c[2])
2022-03-30 20:03:13 +00:00
printf("OK\n");
else
printf("ZLE\n");
return 0;
}