Answer to Question #345282 in C++ for Ali

Question #345282

Looping problem:-

Input two positive integers a and b from the user. Determine the remainder of a/b. Assume that the division and modulus operators are not available.


1
Expert's answer
2022-05-30T08:15:20-0400
#include <iostream>
#include <math.h>
using namespace std;

int main() {
     int a,b,quotient ;
     
     cout<<"Enter a:  ";
     cin >> a;
     cout<<"Enter b:  ";     
     cin >> b;
     
    a = abs(a);
      b = abs( b);
     
  quotient  = 0;
  while (a >= b) {
    a -= b;
    ++quotient ;
  }
     
    cout<< "a/b = "<< quotient<<endl ;
    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
APPROVED BY CLIENTS