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?
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:

Consider n=1:10.Summing numbers that are multiples of 4 and 7 give 19 (ie. 4+7+8=19). What would...
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 a specific number, consider all the numbers from 1 to given number and calculate how many of them are odd, even and multiples of 3. For instance: number = 9 then consider {1, 2, 3, 4, 5, 6, 7, 8, 9} count of even numbers = 4 // 2, 4, 6, 8 count of odd numbers = 5 // 1, 3, 5, 7, 9 count of multiples 3 = 3 // 3, 6, 9 note. You do not...
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 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 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 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)
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....
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...
Consider a sample with data values of 8, 10, 7, 19, and 16. Compute the variance. (to 1 decimal) Compute the standard deviation. (to 2 decimals)
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...