You are doing integer arithmetic, so there the result is correct. Try
percentage=((double)number/total)*100;
BTW the %f
expects a double
not a float
. By pure luck that is converted here, so it works out well. But generally you'd mostly use double
as floating point type in C nowadays.