Algorithms
Logic
Algebra
Mathematics
int foo(int n){ if (n < 0) { return 0; } int count_3 = n / 3; int count_7 = n / 7; int count_21 = n / 21; return count_3 *(3 + n - n % 3) /2 + count_7 *(7 + n- n % 7) / 2 - count_21 *(21 + n - n % 21) /2; }
- int foo(int n){
int sum=0;for (int i =1; i <= n; i++){if (i % 3 == 0 || i % 7 == 0){sum+=i;}}if (n==1){return 1;}elsereturn sum;- if (n < 0) {
- return 0;
- }
- int count_3 = n / 3;
- int count_7 = n / 7;
- int count_21 = n / 21;
- return
- count_3 *(3 + n - n % 3) /2 +
- count_7 *(7 + n- n % 7) / 2 -
- count_21 *(21 + n - n % 21) /2;
- }
// TODO: Replace examples and use TDD by writing your own tests. The code provided here is just a how-to example. #include <criterion/criterion.h> // replace with the actual method being tested int foo(int); Test(the_multiply_function, should_pass_all_the_tests_provided) { cr_assert_eq(foo(10), 25); }
- // TODO: Replace examples and use TDD by writing your own tests. The code provided here is just a how-to example.
- #include <criterion/criterion.h>
- // replace with the actual method being tested
int foo(int,int);- int foo(int);
- Test(the_multiply_function, should_pass_all_the_tests_provided) {
cr_assert_eq(foo(1, 1), 1);- cr_assert_eq(foo(10), 25);
- }