pvjc22/du4/program.c

48 lines
779 B
C
Raw Normal View History

2022-03-30 20:03:13 +00:00
#include <stdio.h>
2022-03-30 21:36:37 +00:00
int main(){
2022-03-30 21:43:10 +00:00
int c[999];
2022-03-31 08:46:47 +00:00
int i = 0;
int vysledok;
2022-03-30 21:36:37 +00:00
char riadok[999];
char *endptr = NULL;
2022-03-30 21:43:10 +00:00
char need;
2022-03-30 20:03:13 +00:00
while(1){
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 == '+'){
2022-03-30 21:43:10 +00:00
need = *r;
2022-03-30 21:36:37 +00:00
continue;
}else if(*r == '-'){
2022-03-30 21:43:10 +00:00
need = *r;
2022-03-30 21:36:37 +00:00
continue;
}else if(*r == '/'){
2022-03-30 21:43:10 +00:00
need = *r;
2022-03-30 21:36:37 +00:00
continue;
}else if(*r == '*'){
2022-03-30 21:43:10 +00:00
need = *r;
2022-03-30 21:36:37 +00:00
continue;
2022-03-30 20:03:13 +00:00
}else{
2022-03-30 21:43:10 +00:00
int v = strtod(riadok,&endptr);
c[i++] = v;
continue;
2022-03-30 20:03:13 +00:00
}
}
2022-03-30 21:43:10 +00:00
if(need == '+')
vysledok = c[0] + c[1];
2022-03-30 21:43:10 +00:00
else if(need == '-')
vysledok = c[0] - c[1];
2022-03-30 21:43:10 +00:00
else if(need == '/')
vysledok = c[0] / c[1];
2022-03-30 21:43:10 +00:00
else if(need == '*')
vysledok = c[0] * c[1];
2022-03-30 21:43:10 +00:00
if(vysledok == c[i])
2022-03-30 20:03:13 +00:00
printf("OK\n");
else
printf("ZLE\n");
return 0;
2022-03-30 21:43:10 +00:00
}