Изменил(а) на 'du4/program.c'

This commit is contained in:
Yaroslav Orlianskyi 2022-03-30 21:37:59 +00:00
parent f0d910c22f
commit 6f81912e02

View File

@ -1,57 +1,54 @@
#include <stdio.h> #include <stdio.h>
#include <stdbool.h>
int main (){ int main(){
int c[2];
int a, i = 0;
int vysledok;
char riadok[999]; char riadok[999];
char *endptr = NULL; char *endptr = NULL;
char need; bool first = true;
int i, a, vysledok = 0; bool second = false;
float c[99];
while(1){ while(1){
a++;
char* r = fgets(riadok,999,stdin); char* r = fgets(riadok,999,stdin);
riadok[i++] = *r; if(*r == '\n'){
if(*r == '\n')
break; break;
} }else if(*r == ' ')
int j = 0;
do{
if(riadok[j] == ' '){
j++;
continue; continue;
}else if(riadok[j] == '+'){ else if(*r == '+'){
need = riadok[j]; first = true;
j++; second = true;;
continue; continue;
}else if(riadok[i] == '/'){ }else if(*r == '-'){
need = riadok[j]; first = false;
j++; second = false;
continue; continue;
}else if(riadok[i] == '-'){ }else if(*r == '/'){
need = riadok[j]; first = true;
j++; second = false;
continue; continue;
}else if(riadok[j] == '*'){ }else if(*r == '*'){
need = riadok[j]; first = false;
j++; second = true;
continue;
}else if(riadok[j] == '='){
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];
j++;
continue; continue;
}else{ }else{
float v = strtod(riadok,&endptr); float v = strtod(riadok,&endptr);
c[a] = v; c[i++] = v;
a = a + 1; continue;
} }
}while(j < i); }
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]) if(vysledok == c[2])
printf("OK\n"); printf("OK\n");
else else
printf("ZLE\n"); printf("ZLE\n");
} return 0;
}