+ 1
Closest smallest integer
Hello, how do I get closest snallest value when diving 2 integers? ex: a =14; b =3; c = a/ b; //I need to get value 4 (smallest closest is 12) Thanks! :)
1 Réponse
+ 1
in fact you will get a 4 your way
int a,b,c;
a =14;
b =3;
c = a/ b; /* c is 4 */
This is called an integer dividion. When the variables are integer, and results variable (c) so integer, the result is too an integer (without decimal places)
Or you can use a % operator, which calcs a remainder from integer dividion.
int a,b,c;
a =14;
b =3;
c = a%b; // c is the remainder=2,
a=a-c; // this is 12, the closest integer dividion