/* * Sample solution for a beginning C exercise to write multiply functions. */ #include /* * Return m*n. * Computes the product iteratively with a for-loop. */ int mult_for(int m, int n) { int result = 0; int i; for (i = n; i > 0; i -= 1) result += m; return (result); } /* * Return m*n. * Computes the product iteratively with a while-loop. */ int mult_while(int m, int n) { int result = 0; int i = n; while (i > 0) { result += m; i -= 1; } return (result); } int main(void) { int m = 3; int n = 5; printf("%d * %d is %d = %d.\n", m, n, mult_for(m, n), mult_while(m, n)); return (0); }