Question

Write a for loop that assigns summed Value with the sum of all odd values from 1 to user Num. Assume userNum is always greate
0 0
Add a comment Improve this question Transcribed image text
Answer #1
function summedValue = OddsSum(userNum)
    summedValue = 0;
    for n=1:2:userNum
        summedValue = summedValue+n;
    end
end


Add a comment
Know the answer?
Add Answer to:
Write a for loop that assigns summed Value with the sum of all odd values from...
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
  • Small aircraft weight limit Write an if-else statement that assigns safetyCheck with 1 if the sum...

    Small aircraft weight limit Write an if-else statement that assigns safetyCheck with 1 if the sum of passengerWeight and cargoWeight is less than or equal maxWeight. Otherwise, assign safetyCheck with 0. Ex: If passengerWeight is 200, cargoWeight is 100, and maxWeight is 500, then safetyCheck is assigned with 1. If passengerWeight is 300, cargoWeight is 275, and maxWeight is 500, then safetyCheck is assigned with 0. Function Save C Reset DI MATLAB Documentation 1 function safetyCheck = CargoLimit(passengerWeight, cargoweight) 2...

  • Write a function to calculate the sum of the reciprocals of a series of odd numbers....

    Write a function to calculate the sum of the reciprocals of a series of odd numbers. The function will have one input and no output, with the input being the ending value for the series of odd values. Write the function definition statement Initialize a variable to zero. This variable will contain the sum of all the values. Create a for loop that loops over all odd numbers from 1 to the specified ending value. Inside the loop, add the...

  • write matlab script 5. Use a for loop to sum the elements in x = [1...

    write matlab script 5. Use a for loop to sum the elements in x = [1 2 3 4 5] Check your answer with sum function 6. Use a while loop to sum the elements in x = [1 2 3 4 5] Check your answer with sum function

  • MATLAB Required!! Write a MATLAB program named whileadder, to nput a desired maximum value. Be sure...

    MATLAB Required!! Write a MATLAB program named whileadder, to nput a desired maximum value. Be sure it is one value only Compute a running total by ones Return as output the last integer that can be added before the total exceeds max For example, if input max 60, the output should 10, because 1+2+3+4+5+6+7+8+9+10 : 55 and adding 11 would make the sum > 60M max- 55, then the output would be 10. Your Function C Reset MATLAB Documentation function...

  • Write pseudocode while loop to sum all the values between 2 integers (A & B, input...

    Write pseudocode while loop to sum all the values between 2 integers (A & B, input by the user), including A and B, and print the resulting sum. A must be less than B, otherwise print 0.

  • Write a C program to sum up all the odd numbers between a lower limit number...

    Write a C program to sum up all the odd numbers between a lower limit number and an upper limit number provided by a user. The requirements are: First, request the user to provide a lower limit integer number and an upper limit integer number that is larger than the lower limit number, and save them in variables lowerLimit and upperLimit, respectively. If the user has entered an upper limit number (upper Limit) that is NOT larger than the lower...

  • Write an expression that executes the loop while the user enters a number greater than or...

    Write an expression that executes the loop while the user enters a number greater than or equal to 0. Note: These activities may test code with different test values. This activity will perform three tests, with userNum initially 9 and user input of 5, 2, -1, then with userNum initially 0 and user input of -17, then with userNum initially -1. See "How to Use zyBooks". . Also note: If the submitted code has an infinite loop, the system will...

  • Linear-spaced points array struct a row array plotPoints with 5 values that are spaced linearly from...

    Linear-spaced points array struct a row array plotPoints with 5 values that are spaced linearly from lowValue to highValue. Hint: Use the linspace function Ex: If lowValue is 1 and highValue is 10, plotPoints is [1.0000, 3.2500, 5.5000, 7.7500, 10.0000] Your Function Save Reset叩MATLAB Documentation 1: function plotPoints-CreatePoints(lowalue, highValue) 21% lowalue: Starting value in plotPoints % highvalue: Ending value in plotPo ints % construct a row array plotPoints with 5 linear-spaced % point from 10«Value to highvalue plotPoints = 0;...

  • 1. Write a for loop that prints the sum of all positive even integers less than...

    1. Write a for loop that prints the sum of all positive even integers less than 200. Assume that variables i and sum are already declared. 2. Write a while loop that prints the sum of all positive odd integers less than 100. Assume that variables i and sum are already declared. 3. Write a do-while loop that prints the sum of all positive multiples of 3 less than or equal to 150. Assume that variables i and sum are...

  • Write an expression that executes the loop while the user enters a number greater than or...

    Write an expression that executes the loop while the user enters a number greater than or equal to 0. Note: These activities may test code with different test values. This activity will perform three tests, with user input of 9, 5, 2, -1, then with user input of 0, -17, then with user input of 0 1 0 -1. Also note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds,...

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