program.c
This commit is contained in:
parent
4fa8cca6a1
commit
7ba9b3ef0b
64
du4/program.c
Normal file
64
du4/program.c
Normal file
@ -0,0 +1,64 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
int main(){
|
||||
|
||||
char vstup[100];
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
char znamienko;
|
||||
|
||||
while(fgets(vstup, 100, stdin)==NULL || *vstup=='\n'){
|
||||
if(sscanf(vstup, "%f %c %f = %f", &x, znamienko ,&y ,&z)!=4){
|
||||
printf("CHYBA\n");
|
||||
continue;
|
||||
}
|
||||
if(znamienko == '+'){
|
||||
float rozdiel;
|
||||
rozdiel=(x+y)-z;
|
||||
if(rozdiel>-0.001 && rozdiel<0.001){
|
||||
printf("OK\n");
|
||||
}
|
||||
else{
|
||||
printf("ZLE\n");
|
||||
}
|
||||
}
|
||||
else if(znamienko == '-'){
|
||||
float rozdiel;
|
||||
rozdiel=(x-y)-z;
|
||||
if(rozdiel>-0.001 && rozdiel<0.001){
|
||||
printf("OK\n");
|
||||
}
|
||||
else{
|
||||
printf("ZLE\n");
|
||||
}
|
||||
}
|
||||
else if(znamienko == '*'){
|
||||
float rozdiel;
|
||||
rozdiel=(x*y)-z;
|
||||
if(rozdiel>-0.001 && rozdiel<0.001){
|
||||
printf("OK\n");
|
||||
}
|
||||
else{
|
||||
printf("ZLE\n");
|
||||
}
|
||||
}
|
||||
else if(znamienko == '/'){
|
||||
float rozdiel;
|
||||
rozdiel=(x/y)-z;
|
||||
if(rozdiel>-0.001 && rozdiel<0.001){
|
||||
printf("OK\n");
|
||||
}
|
||||
else{
|
||||
printf("ZLE\n");
|
||||
}
|
||||
}
|
||||
else{
|
||||
printf("CHYBA\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user