-
Code using namespace std; string even_numbers_from_interval(int a, int b) { string r; for (a % 2 ? ++a : a; a <= b; a += 2) r += to_string(a) + " "; if (r.size()) r.pop_back(); return r; }
Test Cases // TODO: Replace examples and use TDD by writing your own tests Describe(any_group_name_you_want) { It(should_do_something) { Assert::That(even_numbers_from_interval(2, 10), Equals("2 4 6 8 10")); Assert::That(even_numbers_from_interval(9, 14), Equals("10 12 14")); } };
Output:
-
Code - #include <string>
- using namespace std;
- string even_numbers_from_interval(int a, int b) {
//- string r;
- for (a % 2 ? ++a : a; a <= b; a += 2) r += to_string(a) + " ";
- if (r.size()) r.pop_back();
- return r;
- }
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}