fahimkamal63

Modulus of double

Apr 16th, 2019
726
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. double find_mod(double a, double b){
  5.     if(a < 0) a = -a;
  6.     if(b < 0) b = -b;
  7.  
  8.     double mod = a;
  9.     while(mod >= b){
  10.         mod = mod - b;
  11.     }
  12.     if(a < 0){
  13.         mod = -mod;
  14.     }
  15.     return mod;
  16. }
  17.  
  18. int main(){
  19.     int t; cin >> t;
  20.     while(t--){
  21.         double a, b;
  22.         cin >> a >> b;
  23.         cout << find_mod(a, b) << endl;
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment