Assume a and b positive integers.
int Naive(int a, int b) // Naive algorithm { int x = a, y = b, z = 0; while (x > 0) { z += y; x--; } return z; }
Animated example.