Question

1. Type a 'sumade2en2' function that receives an n number and returns the sum of the...

1. Type a 'sumade2en2' function that receives an n number and returns the sum of the numbers from 1 and
increments of 2 without going over n. For example, if the function is invoked with 7, it must return 16 (1+3+5+7). Yes
invoked with the 8 must return 16 (1+3+5+7).

2. Type a 'productmultiply' function that receives two integers a and b. The function must return the
product of all multiples of a that do not exceed b. For example, if the function is invoked with 7 and 30,
57624 (7*14*21*28). If the function is invoked with 6 and 18, it must return 1296 (6*12*18).

Homework Answers

Answer #1

1.

CODE:

int sumaden2en2(int n)
{
int sum=0;

for(int i=1;i<=n;i+=2)
{
sum+=i;
}

return sum;
}

SCREENSHOT:

2.

CODE:

int productmultiply(int a, int b)
{
int product=1;

for(int i=1;(a*i)<=b;i++)
{
product=product*(a*i);
}
return product;
}

SCREENSHOT:

Know the answer?
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
Similar Questions
Python Question: Write a function which returns the sum of squares of the integers 1 to...
Python Question: Write a function which returns the sum of squares of the integers 1 to n. For example, the sum of the squares from 1 to 4 is 1 + 4 + 9 + 16, or 30. You may choose what should be returned if n == 0 You may not use the built-in Python sum function. The Solution Must be recursive >>> sum_of_squares(1) 1 >>> sum_of_squares(4) 30 >>> sum_of_squares(8) # 64 + 49 + 36 + ... +...
Python: Write a function called sum_odd that takes two parameters, then calculates and returns the sum...
Python: Write a function called sum_odd that takes two parameters, then calculates and returns the sum of the odd numbers between the two given integers. The sum should include the two given integers, if they are odd. You can assume the arguments will always be positive integers, and the first smaller than or equal to the second. To get full credit on this problem, you must define at least 1 function, use at least 1 loop, and use at least...
1.Write a function which takes in a dictionary are returns the sum of the keys plus...
1.Write a function which takes in a dictionary are returns the sum of the keys plus the sum of the values, but only if all the keys and all the values are integers. Otherwise it returns False. >>>f({'a':1,'b':4,'c':7,'d':11}) False >>>f({1:2,3:4,5:6,7:8}) 36 2.Write a function to quickly compute the recaman sequence. 3. The Hofstadter Conway sequence is defined by a(1)=a(2)=1 and (for n>2 by) a(n)=a(a(n-1))+a(n-a(n-1)). Write a function to quickly compute this sequence. >>> [hc(i) for i in range(1,20)] [1, 1,...
Complete following function which receives an array of integers and the length of the array, and...
Complete following function which receives an array of integers and the length of the array, and then returns the sum of all the positive numbers in the array. For example, if an array that is passed to this function contains following numbers: -1, 2, 0, 3, 4, -3, 0, 2, 0, and then the return value of the function should be 11. Will this function be working correctly? Yes or No? int sumPositive(int a[],int length) { int s=0;     for(int...
Write a solution to the subset sum problem using Drracket. Write a procedure (subset-sum n nums)...
Write a solution to the subset sum problem using Drracket. Write a procedure (subset-sum n nums) where n is an integer and nums is a list of numbers that returns a subset of the numbers in the list nums whose values sum to n. If no subset of nums does this, the function should return #f. Ex: (subset-sum 12 '(2 10 5 7 3 8 6)) returns '(2 10) or any other subset of '(2 10 5 7 3 8...
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to...
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to N. The function calculateSum has one parameter N of type integer and returns an integer which represents the sum from -1 to N, inclusive. Write another function calculateAverage that calculates an average. This function will have two parameters: the sum and the number of items. It returns the average (of type float). The main function should be responsible for all inputs and outputs. Your...
Write a MASM program that computes the sum of the integers from 1 to N where...
Write a MASM program that computes the sum of the integers from 1 to N where N is a positive integer. Use the equal sign directive to define N. Save the sum in the EAX register. You must use loops. For example, 1 = 1 1 + 2 = 3 1 + 2 + 3 = 6 1 + 2 + 3 + 4 = 10 1 + 2 + 3 + 4 + 5 = 15 Language ( Assembly)...
A function called sum that takes n as a parameter and then returns the value of...
A function called sum that takes n as a parameter and then returns the value of 13+23+33+...+n3.Sample command => output:(display (sum 5)) => 225
write a recursive racket function "sum-alternate" that takes a positive integer x as a parameter. The...
write a recursive racket function "sum-alternate" that takes a positive integer x as a parameter. The function should return the sum of all the integers x, x-2, x-4, x-6, etc. as long as the numbers are positive. For example, [sum-alternate 5] should evaluate to 5 + 3 + 1, and [sum-alternate 6] should evaluate to 6+4+2.
Function Example: Write a Python function that receives two integer arguments and writes out their sum...
Function Example: Write a Python function that receives two integer arguments and writes out their sum and their product. Assume no global variables. def writer(n1, n2): sum = n1 + n2 product = n1*n2 print("For the numbers", n1, "and", n2) print("the sum is", sum) print("and the product is", product) ... 1) Create a PYHW2 document that will contain your algorithms in flowchart and pseudocode form along with your screen shots of the running program. 2) Create the algorithm in both...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT