in c++ 1. Write a code which accept two floating point numbers as an argument. Calculate their modulus and return modulus to the main.
#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;
}
Comments
Leave a comment