c - Why the division of two integers return 0.00? -


this question has answer here:

every time run program different , weird results. why that?

#include <stdio.h>  int main(void) {     int = 5, b = 2;     printf("%.2f", a/b);     return 0; } 

printf("%.2f", a/b); 

the output of division again of type int , not float.

  1. you using wrong format specifier lead undefined behavior.
  2. you need have variables of type float perform operation doing.

the right format specifier print out int %d


Comments