
















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

















































int square(int val) { int result = 0; int counter = 0; while (counter < val) { result += val; counter++; } return result; }
Problem: does this function work?
resultn = val * countern
result 0 = val * counter 0
resultk+1 = (val * counter (^) k) + val = val * (counterk + 1) = val * counterk+1 (by using (3))
continued Docsity.com
int exp(int b, int m) // return b m { int res = 1; while (m > 0) { res = res * b; m = m - 1; } return res; }
Problem: does this function work?
1 * bm^ = bm
res (^) k * bmk^ = bm^ (1)
res (^) k+1 = res (^) k * b (2) mk+1 = mk - 1 (3)
continued Docsity.com
continued Docsity.com