Floating Point Comparison C++ - Finding maximum -
When I compare floating point, I get printed inf in the output screen Can help? When I tried to exclude this snippet, I would like the output I do not know what's wrong with this. For only one comparison, we can use fibers (), is there any other special way to find out more numbers in the float? The loop has its first recurrence, Fix the code so that you do not divide by 0.
unsigned longer temporarily; Long double tempDec = 0.0, max = 0.0; Unsigned long maxInd = 0, j = 0; (Unsigned for long I = 1; i & lt; 100; i ++) for {j = i-1; Temporary = 0; While (h> gt; 0) {if (returnGCD (j, i) == 1) {temp ++; } J--; } TempDec = ((long dual) i) / ((double long) temporary); If (tempDec> max) {max = tempDec; maxInd = I; }} Cout & lt; & Lt; Max. & Lt; & Lt; "#" & lt; & Lt; Maximum end lieutenant; & Lt; Endl;
inf # 1
temp = 0 ,
j = 0 create
tempDec due to division by 0.
if (tempDec> max) will be true for the first time and
max From that onwards,
if will always be false.
Comments
Post a Comment