Develop a function odd_even that determines whether a number is odd or even. It must have the following features: ▪ It must take in a scalar value x Its output is a character value y. • If the value is odd, set the output equal to odd, otherwise, set it to even. • If the value of x provided by the user is not scalar, set the output equal to non-scalar. • If the value of x provided by the user is not a whole number, round it down to the nearest whole number, then proceed in determining whether it is odd or even.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

How do I create this code in MATLAB?

Develop a function odd_even that determines whether a number is odd or even. It must have the following features:
■ It must take in a scalar value x.
Its output is a character value y.
▪ If the value is odd, set the output equal to odd, otherwise, set it to even.
If the value of x provided by the user is not scalar, set the output equal to non-scalar.
■ If the value of x provided by the user is not a whole number, round it down to the nearest whole number, then proceed in determining whether it is odd or even.
Transcribed Image Text:Develop a function odd_even that determines whether a number is odd or even. It must have the following features: ■ It must take in a scalar value x. Its output is a character value y. ▪ If the value is odd, set the output equal to odd, otherwise, set it to even. If the value of x provided by the user is not scalar, set the output equal to non-scalar. ■ If the value of x provided by the user is not a whole number, round it down to the nearest whole number, then proceed in determining whether it is odd or even.
1 function y = odd_even(x)
Code to call your function >
1 oe1 = odd_even (7)
2 oe2 odd_even (8)
C Reset
Transcribed Image Text:1 function y = odd_even(x) Code to call your function > 1 oe1 = odd_even (7) 2 oe2 odd_even (8) C Reset
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

How do I make the input rounded down to the nearest whole number?

function y = odd_even(x)
    if ~isscalar(x)
        y='non-scalar';
    else
        if ~isnumeric(x)
            y=odd_even(round(x));
        else
            if mod(x,2)==0
                y='even';
            elseif mod(x,2)~=0
                y='odd';
            end
        end
    end
end

Can the function determine if a whole number is odd?
Can the function determine if a whole number is even?
✔ Can the function determine if the value is non-scalar?
> Is the input rounded down to the nearest whole number?
Variable y has an incorrect value.
20% (20%)
20% (20%)
30% (30%)
0% (30%)
Transcribed Image Text:Can the function determine if a whole number is odd? Can the function determine if a whole number is even? ✔ Can the function determine if the value is non-scalar? > Is the input rounded down to the nearest whole number? Variable y has an incorrect value. 20% (20%) 20% (20%) 30% (30%) 0% (30%)
Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

How do I fix this?

1 function y-odd_even(x)
2 if ~isscalar (x)
3
4
5
6
7
8
9
10
11
12
13
14
15 end
else
end
y='non-scalar';
if isnumeric (x)
Output
y=odd_even (round(x));
else
end
if mod (x,2)==0
y='even';
elseif mod(x, 2)!=0
y='odd';
end
Code to call your function >
1 oe1 odd_even (7)
2 oe2= odd_even (8)
File: solution.m Line: 10 Column: 28
Invalid use of operator.
C Reset
▶ Run Function ?
Transcribed Image Text:1 function y-odd_even(x) 2 if ~isscalar (x) 3 4 5 6 7 8 9 10 11 12 13 14 15 end else end y='non-scalar'; if isnumeric (x) Output y=odd_even (round(x)); else end if mod (x,2)==0 y='even'; elseif mod(x, 2)!=0 y='odd'; end Code to call your function > 1 oe1 odd_even (7) 2 oe2= odd_even (8) File: solution.m Line: 10 Column: 28 Invalid use of operator. C Reset ▶ Run Function ?
Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education