Question: Program Language: MATLab Write code that will sum up all odd numbers (starting at 1) until the sum is greater than 1,000,000 (Only odd numbers!)
Program Language: MATLab
Write code that will sum up all odd numbers (starting at 1) until the sum is greater than 1,000,000 (Only odd numbers!) For example: 1 + 3 + 5 ... + 555 = 1,000, 291 leftarrow This is greater than 1,000,000 so stop adding... Save the final sum in the variable sum (I've already created this for you) Save the count (how many additions you had to make) in a variable called count Use a while loop not change the line below function [result, count] = sum_ odd_ numbers () %Use result to store final sum of odd numbers result t = theta; %Use count to store how many additions were made count = theta; %Write a while loop to add all odd numbers until their total sum is greater than %One million while sum_ odd_ numbers
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
