Home > Back-end >  In addition to the operation results, why change 2 to 2.0 it outputs 3.000000? Please give direction
In addition to the operation results, why change 2 to 2.0 it outputs 3.000000? Please give direction

Time:10-06

 # include 

Int main (void)
{
Int a, b;

Puts (" both Please input two integers: ");
Printf (" Integer a: "); The scanf (" % d ", & amp; A);
Printf (" Integer b: "); The scanf (" % d ", & amp; b);

Printf (" The result is: % f. \ n ", (a + b)/2);

return 0;
}


The final output statements, the output is 0; Change 2 to 2.0, you can output, 3.000000
Why is zero divisor is 2 output?

Thank you very much!

CodePudding user response:

Printf (" The result is: % f. \ n ", (a + b)/2); Integer in addition to the results or integer, use % f output shows a 0
After 2 to 2.0 in addition to the result is floating point Numbers, use % f output can show the correct value

CodePudding user response:

Undefined behavior results without discussion there are many different possible

  • Related