pvjc22/du4/program.c
Yaroslav Orlianskyi 808b9742b4 SAD
2022-03-31 10:46:47 +02:00

48 lines
779 B
C

#include <stdio.h>
int main(){
int c[999];
int i = 0;
int vysledok;
char riadok[999];
char *endptr = NULL;
char need;
while(1){
char* r = fgets(riadok,999,stdin);
if(*r == '\n'){
break;
}else if(*r == ' ')
continue;
else if(*r == '+'){
need = *r;
continue;
}else if(*r == '-'){
need = *r;
continue;
}else if(*r == '/'){
need = *r;
continue;
}else if(*r == '*'){
need = *r;
continue;
}else{
int v = strtod(riadok,&endptr);
c[i++] = v;
continue;
}
}
if(need == '+')
vysledok = c[0] + c[1];
else if(need == '-')
vysledok = c[0] - c[1];
else if(need == '/')
vysledok = c[0] / c[1];
else if(need == '*')
vysledok = c[0] * c[1];
if(vysledok == c[i])
printf("OK\n");
else
printf("ZLE\n");
return 0;
}