INDAPlus21 / INDAPlus21/alholmbe-task-7

Pass

Open
#1 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

**Very well done Alexander!**

Your code looks good!

My only complaint is this single if-statement resulting in a douplicate code pattern.
_Your code_:
```c
if (n % 2 == 0)
{
for (int i = 0; i < n / 2; i++)
sum += values[i];
}
else
{
for (int i = 0; i < (n + 1) / 2; i++)
sum += values[i];
}
```
_With a ternary operator_:
```c
int sum_to = (n % 2 == 0 ? n : n+1) / 2;
// The expression of `sum_to` is not in the for-loop's comparison statement
// because then it would run once every loop cycle.
for (int i = 0; i < sum_to; i++)
sum += values[i];
```

Keep it up!

> Q. How did the programmer die in the shower?
> A. He read the shampoo bottle instructions: Lather. Rinse. Repeat.

Contributor guide

No contributing guide indexed for this repository

Research direction

Locate the C function containing the shown if/else loops and inspect the surrounding assignment context. Refactor the duplicated loop setup as suggested, then verify the program still produces the expected result for both even and odd values of n.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
backend
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.