Aktualizovat „du4/program.c“
This commit is contained in:
parent
4273744aef
commit
08b68b2eab
@ -3,48 +3,83 @@
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
char add(double A, double B, double C,char AC){
|
||||
float CC=A+B;
|
||||
if(CC==(float)C || A+B==C)return printf("OK\n");
|
||||
return printf("ZLE\n");
|
||||
|
||||
|
||||
|
||||
void add(double a, double b, double c,char ac, int result[],int count){
|
||||
float cc=a+b;
|
||||
if(cc==(float)c || a+b==c) result[count]=1;
|
||||
else result[count]=2;
|
||||
}
|
||||
char subtr(double A, double B, double C,char AC){
|
||||
if(A-B==C)return printf("OK\n");
|
||||
return printf("ZLE\n");
|
||||
|
||||
double subtr(double a, double b, double c,char ac, int result[],int count){
|
||||
if(a-b==c) result[count]=1;
|
||||
else result[count]=2;
|
||||
}
|
||||
char multi(double A, double B, double C,char AC){
|
||||
if(A*B==C)return printf("OK\n");
|
||||
return printf("ZLE\n");
|
||||
|
||||
double multi(double a, double b, double c,char ac, int result[],int count){
|
||||
if(a*b==c) result[count]=1;
|
||||
else result[count]=2;
|
||||
}
|
||||
char divi(double A, double B, double C,char AC){
|
||||
float CC=A/B;
|
||||
double Cc=(int)((A/B)*100000);
|
||||
if(CC==C || A/B==C || Cc==(int)(C*100000))return printf("OK\n");
|
||||
return printf("ZLE\n");
|
||||
|
||||
double divi(double a, double b, double c,char ac, int result[],int count){
|
||||
float cc=a/b;
|
||||
double Cc=(int)((a/b)*100000);
|
||||
if(Cc==c || a/b==c || cc==(int)(c*100000)) result[count]=1;
|
||||
else result[count]=2;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
char *str;
|
||||
str=(char*)malloc(100);
|
||||
double a,b,c;
|
||||
char ac,el;
|
||||
int ind=0;
|
||||
for(int i=0;el!='\n';i++){
|
||||
el=getchar();
|
||||
if(isspace(el)){
|
||||
continue;
|
||||
int *result;
|
||||
result=(int*)malloc(100);
|
||||
double a,b,c;
|
||||
char ac,el=0;
|
||||
int count=0;
|
||||
int eof;
|
||||
for(;eof!=EOF;count++){
|
||||
str=(char*)malloc(20);
|
||||
eof=scanf("%s",str);
|
||||
int ind=0;
|
||||
for(int i=0;i<strlen(str);i++){
|
||||
if(isspace(str[i])){
|
||||
continue;
|
||||
}
|
||||
str[ind]=str[i];
|
||||
ind++;
|
||||
}
|
||||
str[ind]=el;
|
||||
ind++;
|
||||
sscanf(str,"%lF%c%lF=%lF ",&a,&ac,&b,&c);
|
||||
switch(ac){
|
||||
case '+':
|
||||
add(a,b,c,ac,result,count);
|
||||
break;
|
||||
case '-':
|
||||
subtr(a,b,c,ac,result,count);
|
||||
break;
|
||||
case '*':
|
||||
multi(a,b,c,ac,result,count);
|
||||
break;
|
||||
case '/':
|
||||
divi(a,b,c,ac,result,count);
|
||||
break;
|
||||
default:
|
||||
result[count]=3;
|
||||
}
|
||||
free(str);
|
||||
}
|
||||
sscanf(str,"%lF%c%lF=%lF ",&a,&ac,&b,&c);
|
||||
if(ac=='+')add(a,b,c,ac);
|
||||
else if(ac=='-')subtr(a,b,c,ac);
|
||||
else if(ac=='*')multi(a,b,c,ac);
|
||||
else if(ac=='/')divi(a,b,c,ac);
|
||||
else printf("CHYBA\n");
|
||||
count--;
|
||||
for(int j=0;j<count;j++){
|
||||
if(result[j]==1) printf("OK\n");
|
||||
if(result[j]==2) printf("ZLE\n");
|
||||
if(result[j]==3) printf("CHYBA\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user