// D test program div_mod.d CSE413 6/99 // 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(a, b) { return a - div(a,b)*b; } // = a div b for positive integers a, b int div(a, 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,b,c ; a = get(); b = get(); c = put ( div(a,b)); c = put ( mod(a,b)); return 0; }