# include <stdio.h>
int main ()
{
int i=2;
printf("%d\n", 8*i/3);
/* Note: Integer arithmetic performed on 16/3 => 5 */
printf("%d\n", 8.0*i);
/* Error 1: Float value can't be printed with %d (int) specifier,prints 0 instead of 16.000*/
printf("%f\n",8*i);
/* Error 2: Float specifier can't print int value, prints 0.000 instead of 16*/
printf("%f\n",8*i/3);
/* Error 3: Again wrong specifier, Prints 0.000 instead of 5.000 */
printf("%d\n",8*i%3);
/* Note: Calculates 16mod3, ie the remainder is 1 */
printf("%f\n",8.0*i/3);
/* Correctly prints 5.333 */
return 0;
}
Dinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.
Search Content
Basic Courses
Advance Courses