Answer to Question #207142 in C++ for Aroosha ch

Question #207142

in c++ 1.      Write a code which accept two floating point numbers as an argument. Calculate their modulus and return modulus to the main.


1
Expert's answer
2021-06-15T07:08:47-0400
#include <bits/stdc++.h>
using namespace std;
 
double Mod(double a, double b)
{
    double mod;
    if (a < 0)
        mod = -a;
    else
        mod =  a;
    if (b < 0)
        b = -b;
    while (mod >= b)
        mod = mod - b;
    if (a < 0)
        return -mod;
 
    return mod;
}
int main()
{
    double a,b;
    cin >>a ;
    cin >> b;
    cout << Mod(a, b);
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog