53 lines
1.1 KiB
C
53 lines
1.1 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <math.h>
|
|
#include <ctype.h>
|
|
#include <stdlib.h>
|
|
|
|
int main(){
|
|
|
|
char pole[100];
|
|
char* a = fgets(pole, 100, stdin);
|
|
double cislo1;
|
|
double cislo2;
|
|
double vysledok;
|
|
char znamienko;
|
|
char* token;
|
|
|
|
token = strtok(pole, " "); //rozdelenie retazca podla medzier
|
|
cislo1 = atof(token); // premena stringu na desatinne cislo a priradenie cislu1
|
|
token = strtok(NULL, " "); //pokracovanie v rozdelovani retazca
|
|
znamienko = token[0]; // vrati ukazatel na nasledujuci token, cize znamienko
|
|
token = strtok(NULL, " =\n");
|
|
cislo2 = atof(token);
|
|
token = strtok(NULL, " =\n");
|
|
vysledok = atof(token);
|
|
|
|
double realny;
|
|
|
|
switch (znamienko){
|
|
case '+':
|
|
realny = cislo1 + cislo2;
|
|
break;
|
|
case '-':
|
|
realny = cislo1 - cislo2;
|
|
break;
|
|
case '*':
|
|
realny = cislo1 * cislo2;
|
|
break;
|
|
case '/':
|
|
realny =cislo1 / cislo2;
|
|
break;
|
|
default:
|
|
printf("CHYBA\n");
|
|
return 1;
|
|
}
|
|
if (realny == vysledok){
|
|
printf ("OK\n");
|
|
}
|
|
else{
|
|
printf ("ZLE\n");
|
|
}
|
|
|
|
return 0;
|
|
} |