// D test program div_mod.d CSE413 6/99, rev 5/00 // Software division and mod, using repeated subtraction. // read two positive numbers x and y, then print x/y and x%y // = a%b int mod(int a, int b) { return a - div(a,b)*b; } // = a div b for positive integers a, b int div(int a,int b) { int div; div = 0; while (a > b) { a = a - b; div = div + 1; } if (a == b) div = div + 1; return(div); } int main() { int a;int b; int c; a = get(); b = get(); c = put ( div(a,b) ); c = put ( mod(a,b) ); return 0; }