pvjc22/du4/program.c

55 lines
1013 B
C
Raw Normal View History

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