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.
#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;
}
Comments
Leave a comment