-1

I am beginner at programming and I am just writing a very simple program to return the solution of 23/5. My code is below:

float res  = 23/5;
printf("%.3f", res);

The expected answer is 4.6, however, the code outputs: 4.000.

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
Albert
  • 13
  • 4

1 Answers1

0

You are setting its value to an int

float res  = 23.0f/5.0f;
printf("%.3f", res);
mitchell
  • 298
  • 1
  • 11