Update 'du4/program.c'

This commit is contained in:
Mikita Sidarenka 2022-03-31 08:08:20 +00:00
parent 64f396ea27
commit 54954c47cc

View File

@ -1,158 +1,77 @@
#include <stdio.h> #include<stdio.h>
#include <math.h> #include<math.h>
#include <stdlib.h> struct try
#include <string.h> {
#include <ctype.h> double number1;
char array[100]; char sign;
char array1[100]; double number2;
char number1[100]; double final;
char number2[100]; };
char answer[100]; void ok();
int p=0; void zle();
float zero=0;
char znak1;
char znak2;
float firstN=0;
float secondN=0;
float answer1=0;
float myAnswer=0;
char c;
char r;
char q;
int count = 0;
int scan(char* array2){
char* r = fgets(array1,100,stdin);
if (r == NULL){
return -1;
}
else{
return 0;
}
}
int main(){ int main(){
scan(array1); struct try y1[20];
int i=0; int idx =0;
while(i<100){ while (5){
i=i+1; int r = scanf("%lf", &y1[idx].number1);
if(array1[i]!='\n'){ if (r == -1){
count=count+1; break;
} }
if(array1[i]=='\n'){ scanf(" %c ", &y1[idx].sign);
if(array1[i+1]=='\n') scanf("%lf", &y1[idx].number2);
{ scanf(" = %lf",&y1[idx].final);
array1[i]='#'; idx=idx+1;
break;
}
}
else
{
count=count+1;
}
} }
i=0; int nikita=0;
int j=0; while (nikita < idx){
int t=0; idx=idx+1;
while(array1[t]!='#'){ if(y1[nikita].sign == '+'){
array[p]=array1[t]; if (round((y1[nikita].number1 + y1[nikita].number2)*100)/100 == y1[nikita].final)
if(array1[t]=='='){ {
t=t+1; ok();
p=p+1; break;
if(array1[t]==' '){ } else{
array[p]=array1[t]; zle();
t=t+1; break;
p=p+1; }
} }
while(array1[t]!=' ') if(y1[nikita].sign == '-'){
{ if (round((y1[nikita].number1 - y1[nikita].number2)*100)/100 == y1[nikita].final){
if(array1[t]=='#'){ ok();
break; break;
} } else{
array[p]=array1[t]; zle();
t=t+1; break;
p=p+1; }
} }
while(array[i]!='\0'){ if(y1[nikita].sign == '*'){
if(array[i]=='+'||array[i]=='-'||array[i]=='/'||array[i]=='*'){ if (round(y1[nikita].number1 * y1[nikita].number2 * 100) / 100 == y1[nikita].final)
break; {
} ok();
else if(array[i]=='1'||array[i]=='2'||array[i]=='3'||array[i]=='4'||array[i]=='5'||array[i]=='6'||array[i]=='7'||array[i]=='8'||array[i]=='9'||array[i]=='0'||array[i]=='.'){ break;
number1[j]= array[i]; } else
i=i+1; {
j=j+1; zle();
} break;
else if(array[i]==' ' || isalpha(array[i])){i++;} }
else{
printf("CHYBA\n"); }
return 0; if(y1[nikita].sign == '/'){
} if (round(y1[nikita].number1 / y1[nikita].number2 * 100) / 100 == y1[nikita].final)
} {
znak1=array[i]; ok();
i=i+1; break;
j=0; } else{
while(array[i]!='='){ zle();
if(array[i]=='1'||array[i]=='2'||array[i]=='3'||array[i]=='4'||array[i]=='5'||array[i]=='6'||array[i]=='7'||array[i]=='8'||array[i]=='9'||array[i]=='0'||array[i]=='.'){ break;
number2[j]=array[i]; }
j=j+1; }
i=i+1;
}
else if(array[i]==' '){
i=i+1;
}
else{
i=i+1;
p=p+1;
}
} }
znak2=array[i]; return 0;
i++; }
j=0; void ok(){
j=0;
while(array[i]=='1'||array[i]=='2'||array[i]=='3'||array[i]=='4'||array[i]=='5'||array[i]=='6'||array[i]=='7'||array[i]=='8'||array[i]=='9'||array[i]=='0'||array[i]==' '||array[i]=='.'){
if(array[i]=='1'||array[i]=='2'||array[i]=='3'||array[i]=='4'||array[i]=='5'||array[i]=='6'||array[i]=='7'||array[i]=='8'||array[i]=='9'||array[i]=='0'||array[i]=='.'){
answer[j]=array[i];
i=i+1;
j=j+1;
}
else if(array[i]==' '){
i=i+1;
}else{
i=i+1;
p=p+1;
}
}
j=0;
float firstN = atof(number1);
float secondN = atof(number2);
float answer1 = atof(answer);
if(znak1=='-'){
myAnswer=firstN-secondN;
}
else if(znak1=='+'){
myAnswer=firstN+secondN;
}
else if(znak1=='/'){
myAnswer=firstN/secondN;
}
else if(znak1=='*'){
myAnswer=firstN*secondN;
}
zero = myAnswer-answer1;
if(zero>=-0.00001&&zero<=0.00001){
printf("OK\n"); printf("OK\n");
}
else{
printf("ZLE\n");
}
i=0;
p=-1;
memset(array,0,100);
}
p=p+1;
t=t+1;
scanf("\n%c",&q);
if(c=='\n'){
return 0;
}
} }
return 0; void zle(){
printf("ZLE\n");
} }