Algorithms
Logic
Algebra
Mathematics
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;
}else
return sum;
}
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; }else return sum; }
const countMultiplesOfKUpToN = (N, k) => Math.floor(N/k),sumLMultiplesOfN = (l, n) => 0.5*n*l*(l+1),sumMultiplesOfAOrBUpToN = (a, b, N) => {const lA = countMultiplesOfKUpToN(N, a),lB = countMultiplesOfKUpToN(N, b),lAB = countMultiplesOfKUpToN(N, a*b),sA = sumLMultiplesOfN(lA, a),sB = sumLMultiplesOfN(lB, b),sAB = sumLMultiplesOfN(lAB, a*b)return sA+sB-sAB}console.log(sumMultiplesOfAOrBUpToN(3,7,30))console.log(sumMultiplesOfAOrBUpToN(3,7,500000000))- 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;
- }else
- return sum;
- }
// 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); Test(the_multiply_function, should_pass_all_the_tests_provided) { cr_assert_eq(foo(1, 1), 1); }
- // 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);
- Test(the_multiply_function, should_pass_all_the_tests_provided) {
- cr_assert_eq(foo(1, 1), 1);
- }