Изменить 'du4/program.c'
This commit is contained in:
parent
6538107f50
commit
cad86a89ca
@ -3,36 +3,38 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
int call(float A, float B, float C, char AC){
|
int call(long double A, long double B, long double C, char AC){
|
||||||
if(AC=='/'&&B==0||AC==('+'||'-'||'*'||'-')){
|
if(AC=='/'&&B==0 || AC==('+'||'-'||'*'||'-')){
|
||||||
return printf("CHYBA\n");
|
return printf("CHYBA\n");
|
||||||
}
|
}
|
||||||
else if(AC=='+'){
|
else if(AC=='+'){
|
||||||
if(A+B==C)return printf("OK\n");
|
if(A+B==C)return printf("OK\n");
|
||||||
return printf("ZLE\n");
|
return printf("ZLE\n");
|
||||||
}
|
}
|
||||||
else if(AC=='-'){
|
if(AC=='-'){
|
||||||
if(A-B==C)return printf("OK\n");
|
if(A-B==C)return printf("OK\n");
|
||||||
return printf("ZLE\n");
|
return printf("ZLE\n");
|
||||||
}
|
}
|
||||||
else if(AC=='*'){
|
if(AC=='*'){
|
||||||
if(A*B==C)return printf("OK\n");
|
if(A*B==C)return printf("OK\n");
|
||||||
return printf("ZLE\n");
|
return printf("ZLE\n");
|
||||||
}
|
}
|
||||||
if(AC=='/'){
|
if(AC=='/'){
|
||||||
float Cc=A/B;
|
long double Cc=A/B;
|
||||||
Cc=(int)(Cc*100000);
|
Cc=(int)(Cc*100000);
|
||||||
Cc=(float)Cc/100000;
|
Cc=(float)Cc/100000;
|
||||||
if(Cc==C)return printf("OK\n");
|
if(Cc==C || A/B==C)return printf("OK\n");
|
||||||
|
// printf("%Lf",Cc);
|
||||||
return printf("ZLE\n");
|
return printf("ZLE\n");
|
||||||
}
|
}
|
||||||
return printf("CHYBA");
|
return printf("CHYBA\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
str=(char*)malloc(100);
|
str=(char*)malloc(100);
|
||||||
float a,b,c;
|
long double a,b,c;
|
||||||
char ac,el;
|
char ac,el;
|
||||||
int ind=0;
|
int ind=0;
|
||||||
for(int i=0;el!='\n';i++){
|
for(int i=0;el!='\n';i++){
|
||||||
@ -43,7 +45,11 @@ for(int i=0;el!='\n';i++){
|
|||||||
str[ind]=el;
|
str[ind]=el;
|
||||||
ind++;
|
ind++;
|
||||||
}
|
}
|
||||||
sscanf(str,"%f%c%f=%f ",&a,&ac,&b,&c);
|
//3␣/␣45␣=␣0.06666↵
|
||||||
|
//scanf("%s",str);
|
||||||
|
sscanf(str,"%Lf%c%Lf=%Lf ",&a,&ac,&b,&c);
|
||||||
|
//printf("\n%f %c %f =%f ",a,ac,b,c);
|
||||||
call(a,b,c,ac);
|
call(a,b,c,ac);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user