pvjc22/du4/program.c

77 lines
2.4 KiB
C
Raw Normal View History

2022-03-29 10:25:20 +00:00
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
2022-03-31 06:02:11 +00:00
#include <math.h>
2022-03-29 10:25:20 +00:00
2022-03-29 10:30:01 +00:00
int main() {
int i,j; // pro cyklus
2022-03-31 06:02:11 +00:00
double number1, number2, summary, rsum, msum; /*aby se mohlo po<70><6F>tat s desetinn<6E>mi <20><>sly*/
char operand, equ; //na<6E><61>t<EFBFBD>n<EFBFBD> znak<61>
scanf("%lf", &number1); // nacte prvni cislo, znamenko, druhe cislo
scanf("%c", &operand);
scanf("%lf", &number2);
scanf("%c", &equ);
scanf("%lf",&msum);
2022-03-29 10:30:01 +00:00
/*pokud se operand rovna deleni a delitel se rovna nule vypise chybu*/
2022-03-31 06:02:11 +00:00
if((operand == '/') && (number2 == 0)){
printf("Nulou sa ned<65> deli<6C>");
2022-03-29 10:30:01 +00:00
}
2022-03-31 06:02:11 +00:00
if(operand !='+' && operand !='-' && operand !='*' && operand !='/'){
return 1;
printf("\n");
}
if(equ !='='){
return 1;
printf("\n");
}
else if(operand=='+'){
rsum=number1+number2;
if(msum==rsum){
printf("OK\n");
2022-03-29 10:30:01 +00:00
}
2022-03-31 06:02:11 +00:00
else{
printf("ZLE\n");
}
printf("%lf\n",rsum);
}
else if(operand=='-'){
rsum=number1-number2;
if(msum==rsum){
printf("OK\n");
}
else{
printf("ZLE\n");
}
printf("%lf\n",rsum);
}
else if(operand=='*'){
rsum=number1*number2;
if(msum==rsum){
printf("OK\n");
}
else{
printf("ZLE\n");
}
printf("%lf\n",rsum);
}
else if(operand=='/'){
rsum=number1/number2;
if(msum==rsum){
printf("OK\n");
}
else{
printf("ZLE\n");
}
printf("%lf\n",rsum);
}
}
2022-03-29 10:30:01 +00:00