#include<iostream.h>
void main()
{
int a,b,q,r;
cout<<"Enter a ";
cin>>a;
cout<<"Enter b ";
cin>>b;
q=a/b;
r=a-q*b;
cout<<"Remender="<<r;
}
Hi
How good is this method in terms of precision? Is this method applicable to all cases? Can I use this code as a function for the replacement of the % operator?
Hello,
I think you could be able to replace % (but why???) with this function, but if you want a function working in all cases, you need to use the biggest integer type your compiler support (such as long long int) - unless you are absolutely sure your operands are never bigger than ints.
When you use %, the compiler decides the operation to perform according to operands' size. With your function, the compiler always recast to <int> and this can be a waste of memory and CPU cycles.
Stick to %, if you can