C++ Online Compiler
Example: Floating Point Modulo in C++
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Floating Point Modulo #include <iostream> #include <cmath> // Required for fmod int main() { // Step 1: Declare floating-point variables double a = 10.5; double b = 3.2; // Step 2: Use fmod for floating-point remainder double result_fmod = fmod(a, b); // Step 3: Test with negative dividend double c = -10.5; double d = 3.2; double result_fmod_neg_div = fmod(c, d); // Step 4: Print the results std::cout << a << " fmod " << b << " = " << result_fmod << std::endl; // Expected: 0.9 std::cout << c << " fmod " << d << " = " << result_fmod_neg_div << std::endl; // Expected: -0.9 return 0; }
Output
Clear
ADVERTISEMENTS