Question

Write a Script file ‘run-divisiblity-check·m. Run a for loop from 1 to 100 with an increment of 1 and using if-else statement print whether the current number in the loop is divisible by 2, 3 or both or neither rem0 command in MATLAB tells the remainder of a variable when divided by a particular number. For instance, if x-3, rem(x, 2) would return 1 and if x-2, rem(x, 2) would be 0 Do a help on rem() command if you need more details and use it accordingly for the problem in hand Results from 1 to 30 is shown in Figure 1. Note: You have to implement the code for numbers from 1 to 100 1 is not divisible by 2 or 3 2 is divisible by 2 3 is divisible by 3 4 is divisible by 2 5 is not divisible by 2 or 3 6 is divisible by 2 and 3 7 is not divisible by 2 or 3 8 is divisible by 2 9 is divisible by 3 10 is divisible by 2 11 is not divisible by 2 or 3 12 is divisible by 2 and 3 13 is not divisible by 2 or 3 14 is divisible by 2 15 is divisible by 3 16 is divisible by 2 17 is not divisible by 2 or 3 18 is divisible by 2 and 3 19 is not divisible by 2 or 3 20 is divisible by 2 21 is divisible by 3 22 is divisible by 2 23 is not divisible by 2 or 3 24 is divisible by 2 and 3 25 is not divisible by 2 or 3 26 is divisible by 2 27 is divisible by 28 is divisible by 2 29 is not divisible by 2 or 3 30 is divisible by 2 and 3 Figure 1: Results for numbers from 1 to 30 [You have to present results from 1 to 100]

0 0
Add a comment Improve this question Transcribed image text
Answer #1

This is the code for your program


for i=1:1:100
  
if(or(mod(i,2),mod(i,3)))
if(and(mod(i,2),mod(i,3)))
fprintf("\n%d divi 2 & 3",i);
elseif(mod(i,2)==0)
fprintf("\n%d divi 2",i);
else
fprintf("\n %d divi 3",i);
end
else
fprintf("\n%d not divi",i);
end
end

Add a comment
Know the answer?
Add Answer to:
Write a Script file ‘run-divisiblity-check·m'. Run a for loop from 1 to 100 with an increment...
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
  • Create a new MATLAB Script file named MT3P3_itname.m. In your script file perform the following calculations:...

    Create a new MATLAB Script file named MT3P3_itname.m. In your script file perform the following calculations: Prompt the user to enter an integer. Use a multiple if-elseif structure to determine the following: Confirm that the number is an integer. If not, the program displays message 1. Check if the number is divisible by 2 and displays message 2. Check if the number is divisible by 3 and displays message 3. For anything other than 1, 2, or 3, the program...

  • Please write a BASH Script in LINUX that... 1. is actually executable 2. has a comment...

    Please write a BASH Script in LINUX that... 1. is actually executable 2. has a comment to tell us what you did, why and how. 3. allows a user to enter their name and a number between 1 than 100 (this must be prompted so the user knows what to do) 4. creates a random number between 1 and 100 for you to guess. The command to create a random number is shown below. (if you find a better one...use...

  • Write a MATLAB script, using either a single or nested for-loop, that will print the factorials...

    Write a MATLAB script, using either a single or nested for-loop, that will print the factorials for the numbers between 1 and 100 (inclusive). The factorial of n (n!) is the product of the positive integers less than or equal to n. For example: 3! = 3 * 2 * 1. For this question you cannot use the built-in MATLAB factorial function, but you can use other MATLAB functions if you wish. MATLAB code!MATLAB code!MATLAB code!MATLAB code!

  • Flowcharts & for loops 1. Using a for loop, write a MatLab script to convert ounces...

    Flowcharts & for loops 1. Using a for loop, write a MatLab script to convert ounces to grams for 0 to 16 ounces, in 1-ounce increments. Present output in a table; label columns appropriately. 2. A Fibonacci sequence is composed of elements created by adding the previous 2 elements. The simplest Fibonacci sequence starts with 1, 1 and proceeds as follows: 1,1,2,3,5,8… Element 3 is the sum of elements 1 and 2 (1+1=2) Element 4 is the sum of elements...

  • Write a program in a script file that finds the smallest odd integer that is also...

    Write a program in a script file that finds the smallest odd integer that is also divisible by 3 and whose cube is greater than 4000. Use a loop in the program. The loop should start from 1 and stop when the number is found. The program should print the message: The required number is: [and then prints the number]

  • USE FOR LOOP INSTEAD OF WHILE LOOP Consider the following script file. Fill in the lines...

    USE FOR LOOP INSTEAD OF WHILE LOOP Consider the following script file. Fill in the lines of the following table with the values that would be displayed immediately after the while statement if you ran the script file. Write in the values the variables have each time the while statement is executed. You might need more or fewer lines in the table. Then type in the file, and run it to check your answers. k = 1; b = -2;...

  • 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

  • Copy/Paste your script from 5b here. 4. Let's look at a more complicated script executable. a....

    Copy/Paste your script from 5b here. 4. Let's look at a more complicated script executable. a. Write the following as script6.sh and change its permissions to count for num in d do if num eq 100 then count (count+1) done echo The number 10 was found $count times What is the output? Run the script as ./script6.sh 10 20 30 10 40 20 50 10 60 <enter Summarize what the script does r using the read command. The following script...

  • (In Linux) 1. Create a file to write to from your script and save it as...

    (In Linux) 1. Create a file to write to from your script and save it as “.txt”. 2. Write the following information to the file that you created in Step 1: Today's date Your full name Your student ID The name of your course What directory you are in File permissions of the file that you created that allow everyone to read, write, and execute The long list of files in your current directory, providing all items and their process...

  • Using MATLAB. Create a script file that calls a user-defined function within a for/end loop to...

    Using MATLAB. Create a script file that calls a user-defined function within a for/end loop to symbolically compute the derivative of ln(x) on the interval from -5 to 5, containing 100 data points. Your script file should output a plot of the derivative of ln(x) (taken from your function) vs x. Use a line with circular markers for the plot and include a grid and appropriate labels. The user-defined function should 1. Receive a single x value as input. 2....

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