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
  • Write a MATLAB script that asks for a number to find the name of the day...

    Write a MATLAB script that asks for a number to find the name of the day in a week. The script must accept numbers between 1 and 7, otherwise must give an error message.

  • 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 script that asks the user to input a number. If the value the user...

    Write a script that asks the user to input a number. If the value the user enters is a negative value, call the pre-defined function neg_value which consumes no arguments and returns no values. If the user enters a positive value, call the pre-defined function pos_value which consumes no arguments and returns no values. If the user enters a zero, display the message "Invalid Value". Doing this on Python. This is what I have: number = int(input("Enter a number: "))...

  • 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...

  • Write a MATLAB script named Converter.m and MATLAB two functions, each in its own script, named...

    Write a MATLAB script named Converter.m and MATLAB two functions, each in its own script, named D2BConverter.m and B2DConverter.m The Selection Output should be the following: Binary to Decimal & Decimal to Binary Converter Please Select: 1. Convert from Decimal To Binary 2. Convert from Binary To Decimal 3. Exit If user select option [1] then you ask the user to enter a decimal number (whole number) and display the equivalent binary, else if the user select option [2] then...

  • Write a script in MATLAB that prompts the user to do a, b, & c. a.)script...

    Write a script in MATLAB that prompts the user to do a, b, & c. a.)script that prompts the user to enter the day of the week using the input function. If the information the user enters is equal to “Saturday” or “Sunday”, display “have a nice weekend” in the Command Window. Otherwise, display “Good luck in your class lectures and your studies.” b.)script that prompts the user to input the following array by providing an example in the prompt:...

  • 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...

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