Closest smallest integer | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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! :)

1st Dec 2017, 6:21 AM
Radek Horáček
Radek Horáček - avatar
1 Answer
+ 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
1st Dec 2017, 9:39 AM
Petr Hatina
Petr Hatina - avatar