+ 3
How '%' operator will work if we use two float numbers ?
It will show error in C but shows some value in python tell me why is it so...
4 odpowiedzi
+ 5
In C/C++ the '%' operator is used to get the reminder and it only works on int numbers if you try to use float number then it will result in error.
For C/C++ Eg:-
5 % 3 = 2
5.3 % 3.2 (It will generate Error )
+ 4
In Python it works the same way it works for integers. Say you want to do 5.3%1.2. Then find the biggest integer multiple of 1.2 not exceeding 5.3. Now 1.2*4=4.8, but 1.2*5=6.0, which is bigger than 5.3. Thus this multiple is 4.8. Now we subtract 4.8 from 5.3 to get the answer 0.5. Done!
Let me know if any of this confuses you.
+ 2
In C/C++, the % operator only works for integers. To get the floating point remainder of a division use the fmod() function.
https://en.cppreference.com/w/cpp/numeric/math/fmod
As for Python:
https://docs.python.org/3/reference/expressions.html#index-66
0
15%4 = 3
20%5= 0
22%6=4
it gives the reminder