Question

In: Computer Science

For this question, you must show all work to receive any credit. DONOT USE MATLAB FOR...

For this question, you must show all work to receive any credit.
DONOT USE MATLAB FOR THIS QUESTION.

for k = 3*1:6:21
j = k/3;
if rem(j,6) >= 3
disp(k)
elseif rem(j,3) < 2
disp(j)
else
disp(3)
end
end

write out the solution

Solutions

Expert Solution

Here I am giving an explanation for the code:
Firstly for loop is given as

k=3*1:6:21 => k=3:6:21 =>k=3,3+6,3+6+6,21 => k=3,9,15,21.

So for loop is iterated 4 times with k= k=3,9,15,21.

Next j=k/3

So j becomes j=1,3,5,7(3/3,9/3,15/3,21/3) after iterationg for loop j changes from starting to ending value.

So loop repeats 4 times

First for k=3 and j=1:

if rem(j,6)>=3

rem(1,6)=1/6 remainder is 1 which is not true so it goes to next ifelse

rem(j,3)<2

rem(j,3)=1 it is less than 2 hence,True. So this ifelse executes and disp(j) is exuted and 1 is shown in output.

Second for k=9 and j=3:

if rem(j,6)>=3

rem(3,6)=3/6 remainder is 3 which is true. So this if executes and disp(k) is exuted and 9 is shown in output.

Thirdly for k=15 and j=5:

if rem(j,6)>=3

rem(5,6)=5/6 remainder is 5 which is true. So this if executes and disp(k) is exuted and 15 is shown in output.

Finally for k=21 and j=7:

if rem(j,6)>=3

rem(7,6)=21/6 remainder is 1 which is not true so it goes to next ifelse

rem(j,3)<2

rem(7,3)=1 it is less than 2 hence,True. So this ifelse executes and disp(j) is exuted and 7 is shown in output.

So output is:
1

9

15

7


Related Solutions

For any mathematical computations, you must show your work to receive full credit. 2. For a...
For any mathematical computations, you must show your work to receive full credit. 2. For a sample of 900 police officers at a local police department, a researcher believes there is a relationship between “number of arrests per month” and “police use of force.” Using the following data, test the null hypothesis at the .01 level of significance that police use of force does not differ by the number of arrests per month that an officer makes. In so doing,...
For any mathematical computations, you must show your work to receive full credit. 7. Two groups...
For any mathematical computations, you must show your work to receive full credit. 7. Two groups of subjects participated in an experiment designed to test the effect of frustration on aggression. The experimental group of 40 subjects received a frustrating puzzle to solve, while the control group of 70 subjects received a very easy version of the same puzzle. Levels of aggression was measured for both groups where higher scores are indicative of higher levels of aggression. The experimental group...
Please show all work to receive credit for the calculation question. Godfrey is an artist that...
Please show all work to receive credit for the calculation question. Godfrey is an artist that paints live portraits for people. If he changed the price of a portrait from $30 to $36 and quantity demanded by customers changed from 300/month to 270/month, What is the price elasticity of demand (e) for his product? Is demand for his product price elastic or price inelastic? Give the criteria used for your conclusion. At what new price (from the original price of...
*Please be sure to fully explain answers You must show work to receive credit. 1.) Use...
*Please be sure to fully explain answers You must show work to receive credit. 1.) Use the information to answer the following questions. A borrower takes a $325,000 mortgage loan from a bank. The terms are the loan are a 30-year term, a rate of 4.75%. (20pts) a. Calculate the fixed monthly payment on this loan. b. What is the total amount of money they would pay if they made every monthly payment and paid no more than the fixed...
fill in the missing information: Must show all your work to receive credit. Case A Case...
fill in the missing information: Must show all your work to receive credit. Case A Case B Case C Units Produced 1,000 1,500 800 Standard hours per unit 3.5 ? 3 Standard hours for production ? ? ? Standard rate per hour $7.25 $7.00 $7.00 Actual hours worked 3,400 4,900 2,330 Actual total labor cost ? $31,850 ? Labor price variance $850 F ? $466 F Labor usage variance ? $2,800 U ? Please show work for how each missing...
Instructions: Show all your work to get partial credit. Answers without any work-even correct-will not receive...
Instructions: Show all your work to get partial credit. Answers without any work-even correct-will not receive any credit. Good Luck! A firm is considering investing in a new project. According to its cost of capital while using debt, preferred stock and new common stock, the project is expected to have an initial after-tax cost of $5,000,000. Furthermore, the project is expected to provide after-tax operating cash flows of $1,800,000 in year 1, $2,900,000 in year 2, $2,700,000 in year 3...
Show all work in the space provided. All work must be shown to obtain full credit....
Show all work in the space provided. All work must be shown to obtain full credit. If a calculator function was used, list exactly what was entered into the calculator. All z-score calculations must be shown. 1. According to one study, the average hours of sleep on a weeknight for men was 6.9 hours with a standard deviation of 1.5 hours. a. Find the proportion of men who sleep for more than 8 hours per night. b. Find the proportion...
. YOU MUST SHOW ALL CALCULATIONS TO EARN CREDIT.                                   &nbsp
. YOU MUST SHOW ALL CALCULATIONS TO EARN CREDIT.                                                                         2016                            2017 BALANCE SHEETS: Assets:                         Cash                                        120,000                       160,000                         Accounts Receivable               520,000                       620,000                         Inventory                                305,000                       290,000                         Fixed Assets, net                    410,000                       510,000                         Total Assets                           1,355,000                    1,580,000 Liabilities and Equity:                         Accounts Payable                   350,000                       $375,000                         Long-term Debt                      500,000                       625,000                         Common Stock                       50,000                         75,000                         Retained Earnings                   455,000                       505,000                         Total Liabilities and Equity    1,355,000                   ...
Complete an ANOVA table given the following information. You must show all work to receive partial...
Complete an ANOVA table given the following information. You must show all work to receive partial credit. Question 1: How does a dog’s tail wag in response to seeing different people and other pets? Owner: 69, 72, 65, 75, 70 Cats: 28, 32, 30, 29, 31 Other dogs: 45, 43, 47, 45, 44 Find the degrees of freedom for each group: (Remember df = N -1) Group 1: Group 2: Group 3: Degrees of freedom (within): Degrees of freedom (total):...
Show all work for credit. Be sure to label work and use sentences as appropriate to...
Show all work for credit. Be sure to label work and use sentences as appropriate to explain what steps you are taking. Be sure to clearly label any steps, results, or conclusions. Mention every single step you do. For the following function f(x) = 2x-5/x+1 Find : (a) (5 points) Find the domain (in interval notation). (b) (5 points)Find any Vertical asymptotes or holes. Provide a written explanation why you are choosing Vertical asymptote or hole. (c) (5 points)Find any...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT