int f (int n) {
int ans = 0;
for (int i = 1; i < n; i++) {
if (i < n/2) {
ans -= i;
}
else {
ans += i;
}
}
return ans;
}
What does f(7) evaluate
Answers
Answered by
2
Answer:
15
Explanation:
If n=7, then
i = 1, 1 < 3, ans = -1
i = 2, 2<3, ans = -1-2 = -3
i = 3, 3=3, ans = -3+3 = 0
i = 4, 4>3, ans = 0+4 = 4
i = 5, 5>3, ans = 4+5=9
i = 6, 6>3, ans = 9+6=15
15 is returned
Similar questions