Question

Write a MATLAB script that asks the user to enter a whole number (i.e., any whole...

Write a MATLAB script that asks the user to enter a whole number (i.e., any whole number, positive, negative or zero). After the number is entered, the program must utilize an IF-ELSE statement and determine the parity of the number. The parity of a number is simply whether it is an even number or an odd number. If the number is even, MATLAB must then generate and display the message: The entered number is an even number. Otherwise, MATLAB must generate and display the message: The entered number is an odd number. (Hint: What basic property of numbers makes them odd or even? What existing MATLAB function that we discussed in class can we take advantage of to determine the parity of numbers?)

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

EDIT RUN C:トUsersトdeekhya Documents MATLAB D Editor - CAUsers deekhya\Documents MATLABlevenodd.m Command Window evenodd.m+ ⓕMATLAB CODE---

clc;
clear all;
close all;

N=input('PLEASE ENTER A WHOLE NUMBER=');

%WE CAN DETERMINE THE PARITY OF NUMBERS USING MOD OR REM FUNCTION
%AVAILABLE.


if(mod(N,2)==0)
fprintf('THE ENTERED NUMBER IS EVEN NUMBER');
else
fprintf('THE ENTERED NUMBER IS ODD');
end


  

Add a comment
Know the answer?
Add Answer to:
Write a MATLAB script that asks the user to enter a whole number (i.e., any whole...
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
  • This question is for MATLAB. Write a script that continuously asks the user for a new...

    This question is for MATLAB. Write a script that continuously asks the user for a new sentence, until the user types the word "STOP". The program records all of the sentences the user wrote (not including "STOP") in a matrix with as many rows as needed but with an N number of columns. The user is prompted to provide N before typing in the first sentence. The output of the program is the array with the sentences in it, in...

  • In Matlab, write a script which asks a user to input numbers until the user inputs...

    In Matlab, write a script which asks a user to input numbers until the user inputs 0. Then the script should print only the positive numbers entered by the user, in reverse order. For example, if the user inputs “4,-1,5,2,-3,-8,0” the script should print “2,5,4”.

  • Write a program that asks the user to type an even number or 111 to stop....

    Write a program that asks the user to type an even number or 111 to stop. When the user types an even number, display the message “Great Work”, and then ask for input again. When the user types an odd number, display the message “Try again” and ask the user to enter again. When the user enters the sentinel value of 111 the program ends I've attempted this but it went horribly wrong. we are only suppose to use while,...

  • Write a Matlab script that asks the user for two angles in degrees and stores them...

    Write a Matlab script that asks the user for two angles in degrees and stores them as variables. Calculate and store the cosines of the numbers (they must be converted to radians to use Matlab's cos function). Use a conditional statement and fprintf to print the larger of the two cosine values and the angle (in degrees) that resulted in that value. If they are equal, print a message to the effect that the cosines of the two angles (print...

  • Write a Java program that: • Asks the user to enter the number of integers that...

    Write a Java program that: • Asks the user to enter the number of integers that he need to enter; • Asked him to enter integer by integer; • Print The number of Odd numbers entered and the number of Even numbers entered. Important notes: 1. You should have to copy and paste the Java as your answer for this question. DON’T take screen shot for your Java Code. It must be editable. 2. Take a screen shot for your...

  • 1) Write a MATLAB script to prompt a user to input two numbers, then assess whether...

    1) Write a MATLAB script to prompt a user to input two numbers, then assess whether the two numbers are equal or not. If the two numbers are equal, display that they are equal in the Command Window. If they are not equal, display that they are not equal in the Command Window. 2) Write a MATLAB script that prompts the user to enter the day of the week using the input function. If the information the user enters is...

  • Allow a user to enter any number of double values up to 15. The user should...

    Allow a user to enter any number of double values up to 15. The user should enter 99999 to quit entering numbers. Display an error message if the user quits without entering any numbers; otherwise, display each entered value and its distance from the average. DistanceFromAverage.java

  • Write a MATLAB script, which asks the user to input the angle xd (in deg) and...

    Write a MATLAB script, which asks the user to input the angle xd (in deg) and then approximates sine of the angle using the first 5 terms of Taylor series as follows: n+12n-1 sin n-1 (2n-1)! 1 Note that x in Taylor's equation is in radian, so make sure to do the conversion first Start with defining the vector n=1:5 and then use element-wise operation and basic MATLAB commands to calculate the summation. To calculate the factorial of any number,...

  • Write a program that asks the user to enter a number ofseconds.• There are...

    Starting Out with C++ (9th Edition)  Chapter 4, Problem 7PCWrite a program that asks the user to enter a number of seconds.• There are 86400 seconds in a day. If the number of seconds entered by the user is greater than or equal to 86400, the program should display the number of days in that many seconds.• There are 3600 seconds in an hour. If the number of seconds entered by the user is less than 86400, but is greater...

  • How to write this code in C++???? using fstream Write a program which: Asks the user...

    How to write this code in C++???? using fstream Write a program which: Asks the user to enter a positive integer greater than 0 Validates that the entry is a positive integer Outputs the digits in reverse order with a space separating the digits Outputs the even digits not in reverse order with a space separating the digits (consider zero to be even) If there are no even digits, the an appropriate message should be displayed: There are no even...

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