Can we use floating variables in if statements in C?

Page 1

Can we use floating variables in if statements in C? Yes, we can use floating variable in if statement but you have to be very careful while initialising the condition C Language. Comparisons between floating-point values (including comparisons with zero) are easily sent “off� by truncation/rounding errors. Yes. You can use. But a direct comparison will never result in a true condition. Remember that floating point values are hardly precise. So what you can do is along with the float value you are comparing, declare another value that serves as an upper and lower bound to your value,

For example:Float a=6.7, b=5.8; if(a==b) { printf("same");


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.