Question

Consider n=1:10.Summing numbers that are multiples of 4 and 7 give 19 (ie. 4+7+8=19). What would...

Consider n=1:10.Summing numbers that are multiples of 4 and 7 give 19 (ie. 4+7+8=19). What would be the sum of these multiples from n=1500:7000?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

sum of integers between 1500 and 7000 (including) which is divisible by 4 or 7 is 8352033, which is shown below in sample output 2.

Here is Matlab Code :

function main
    function s = g(ni, nf)
        x = 0;
        y = 0;
        z = 0;
        for n = ni : nf
            if(mod(n,4)== 0)     %sum of all integers which are divisible by 4
                x = x + n;
            end
            if(mod(n,7) == 0)      %sum of all integers which is divisible by 7
                y = y + n;
            end
            if((mod(n,4)==0) && (mod(n,7)==0))        %sum of all integers which is divisible by both 4 and 7
                z = z + n;
            end
        end
        s = x + y - z;          %sum of all integers which are divisible by 4 or 7, using inclusion exclusion principle
        fprintf("sum = %d\n",s);
    end
    g(1500,7000);
end

Here is c code:

#include <stdio.h>

long int sum(int ni, int nf)
{
    long int x,y,z;
    x=y=z=0;
    long int i = ni;
    while(i<=nf)
    {
       if(i%4 == 0)
           x+=i;
       if(i%7 == 0)
           y+=i;
       if((i%4 == 0) && (i%7 == 0))
           z+=i;
        i++;
    }
    return (x + y - z);
}
int main()
{
    int ni, nf;
    ni = 1500;
    nf = 7000;
    printf("sum of integers between %d and %d (including)\nwhich is divisible by 4 or 7 is : \n", ni, nf);
    printf("sum = %ld\n", sum(ni, nf));
}


Here is output of the code:

sample output 1:

sample output 2:

Add a comment
Know the answer?
Add Answer to:
Consider n=1:10.Summing numbers that are multiples of 4 and 7 give 19 (ie. 4+7+8=19). What would...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 6. Consider the sum of the first 10 numbers: 1+2+3+4+5+6+7+8+9+10. Can you change some of the...

    6. Consider the sum of the first 10 numbers: 1+2+3+4+5+6+7+8+9+10. Can you change some of the plus signs to minus signs so that the resulting sum is 0? For example: 1+2-3-4-5-6+7-8+9+10=3. This is close, but not 0. Provide a solution or show that there isn't one.

  • Given the following sets: S = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10},...

    Given the following sets: S = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, Even numbers A = {2, 4, 6, 8, 10}; Odd number B = {3, 5, 7, 9}; Natural numbers N = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} and Prime numbers C = {2, 3, 5, 7} Find the following: a) A ∪ C b) A ∩ N c) A ’ d) B ∩ N e) B ∪ N f) C...

  • Consider a table of numbers from 1-13. Give me a sql query that finds out the...

    Consider a table of numbers from 1-13. Give me a sql query that finds out the list of missing numbers by start and end. Example 1, 5, 6, 7 Answer: start end 2      4 8      13

  • 1. Find the 20th term in the sequence 4, 6, 8, 10, … 2.  What term of...

    1. Find the 20th term in the sequence 4, 6, 8, 10, … 2.  What term of the sequence 2, 5, 8, … is 74? 3. Find the sum of the series 2 + 5 + 8 + … + 74. (see question 2) 4.  Find the 19th term of the sequence 1, 2 , 2, … 5. What is the sum of the first 16 terms of the sequence 2, 4, 8, …? 6.  A coin is flipped, and a four sided...

  • Write a function that finds the sum of all numbers up to (and including) N that...

    Write a function that finds the sum of all numbers up to (and including) N that are multiples of either x or y. e.g. For N= 10 x=2 y=3 s=2+3 +4 +6+ 8 + 9 + 10 = 42 In [ ]: def multiplesum (N, x, y): returns In [ ]: # Your Provided Sample Test Cases print("#1", multipleSum (10, 2, 3) == 42) print("#2", multipleSum (25,7,8) == 90) print("#3", multipleSum (15,1, 12) == 120)

  • Exercise 4 – Printing out 10 multiples per row Design a function called print_ten_multiples that takes...

    Exercise 4 – Printing out 10 multiples per row Design a function called print_ten_multiples that takes an integer as a parameter. The function should print out the first 10 multiples of all numbers from 1 up to the given number. The values printed should be formatted with "3d". Example: print(format(x, "3d")) Examples of how the function output should look with this formatting: print_ten_multiples(3): 1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 12 14...

  • Java Magic Square: A n x n matrix that is filled with the numbers 1, 2,...

    Java Magic Square: A n x n matrix that is filled with the numbers 1, 2, 3,.... n^2 is a magic square if the sum of the elements in each row, in each column, and in the two diagonals is the same value. I need to write an application that gets 16 values as user input, in any order. Store these values in an ArrayList. When the numbers are put into a square, this would be a 4x4 two-dimensional array....

  • 8. Ann x n matrix that is filled with the numbers 1,2,3, ....n2 is a magic...

    8. Ann x n matrix that is filled with the numbers 1,2,3, ....n2 is a magic square if the sum of the elements in each row, in each column, and in the two main diagonals is the same value. For example, 16 3 213 5 10 11 8 9 6 7 12 4 15 14 1 Write the program that reads in 16 values from the keyboard and tests whether they form a magic square when put into a 4...

  • c++ fibonacci code using loops Here are 8 Fibonacci numbers: 1, 1, 2, 3, 5, 8,...

    c++ fibonacci code using loops Here are 8 Fibonacci numbers: 1, 1, 2, 3, 5, 8, 13, 21 Note that the first Fibonacci number is 1, F(1) = 1 The second Fibonacci number is 1, i.e. F(2) = 1 Other Fibonacci numbers in the sequence is the sum of two previous Fibonacci numbers. For example F(3) = F(2) + F(1). In general F(n) = F(n-1) + F(n-2) Write a program to do the following tasks. User entries are shown in...

  • 1. a) Let A = {2n|n ∈ ℤ} (ie, A is the set of even numbers)...

    1. a) Let A = {2n|n ∈ ℤ} (ie, A is the set of even numbers) and define function f: ℝ → {0,1}, where f(x) = XA(x) That is, f is the characteristic function of set A; it maps elements of the domain that are in set A (ie, those that are even integers) to 1 and all other elements of the domain to 0. By demonstrating a counter-example, show that the function f is not injective (not one-to-one). b)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT