c - Why does 5/7 print 0? -


i started learning c, , learnt / sign division operator. experimenting, , wondering why 5/7 printf number 0.

here program:

#include<stdio.h>  main() {     int n;     n = 5/7;     printf("%d", n); } 

thank you!

this because of integer division. 5/7 makes 0.71.., , integer part of number 0, hence prints 0. solve problem use float type (or double type) variables constants example try:

float f = 5.0 / 7.0; 

print variable f format string %f


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -