Home > Back-end >  C language problem, and master
C language problem, and master

Time:09-27

#include

Int main ()
{
Int d, b;
For (b=0; b<43. B++)
{
For (d=0; d<45. D++)
{if (d> B)
continue;
If (b * * 1.9=2.3 + d=82.3)
Printf (" beer=% d,=% d ", b, d); }
} return 0;
}



Drink 1.9 yuan, 2.3 yuan, a total of buy fewer than drink beer, it took 82.3 yuan, but to run the program did not show anything

CodePudding user response:

If (23 + b * d * 19==823)

CodePudding user response:

Numbers can't a bit

CodePudding user response:

The integer data!

CodePudding user response:

refer to the second floor qq_33794845 response:
digital a bit you
Numbers can be a bit, of course, is quite a bit Numbers are equal here not so, believe generally have on the teaching material, may be you haven't noticed,

CodePudding user response:

Int main ()
{
Int max_b=int (82.3/2.3);
Int max_d=int (82.3/1.9);
Int d, b;
For (b=0; b<=max_b; B++)
For (d=b + 1; d<=max_d; D++)
If (b * * 1.9=2.3 + d=82.3)
Printf (" beer=% d,=% d ", b, d);
return 0;
}

CodePudding user response:

refer to the second floor qq_33794845 response:
digital a bit you

You are integer variables defined, you can put the integer data as an integer, then the integer is certainly without a decimal point, with a decimal point that is floating point is float, textbook you can look at;
Application of all didn't output as a result, because if you wrote (b + d * 1.9 * 2.3==82.3), this condition does not meet all have no output, you can change to & lt;=this condition to see whether the program output;
There are
 if (d> B) 
continue;
the statement according to what you mean can't use the continue, should use the break, meaning from the end of the current loop;

CodePudding user response:

refer to the second floor qq_33794845 response:
digital a bit you


The comparison of floating point Numbers, there may be errors in c + +, add a function to judge yourself

For example,
[code=cbool EqualXy (double Chd_A, double Chd_B)
{
Double Chd_X=Chd_A - Chd_B;
If ((Chd_X & lt; 0.000001) & amp; & (Chd_X & gt; 0.000001))
{
return true;
}
The else
{
return false;
}
}] [/code]
  • Related