Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Time to combine everything Please write the function largestDigit(), that adheres to the following requirements: 1. There is one parameter 2. There is one retum

image text in transcribed

Time to combine everything Please write the function largestDigit(), that adheres to the following requirements: 1. There is one parameter 2. There is one retum value 3. The function must check that the parameter is a integer. If it is not an integer, return -1. 4. The function will check a number, and return the largest digit that is in the number 5. You may assume that the parameter is scalar Hints . Dividing by 10 would effectively shift every number to the right by 1 in terms of number place The rem() or mod() functions may be useful in determining the the digit in the ones place. Simply calculate the remainder when divided by 10. . WHILE LOOPS! For example, if the number is 12345, dividing by 10 and then doing something to it to remove the decimal values would return 1234, which is everything except the last digit. Likewise, the remainder when 12345 is divided by 10 is 5 function out = largestDigit(x) E% function that finds the largest digit in a given number. Returns -1 if % the input is not a whole number % Input: x - a number % Output: out - the largest digit or -1 for invalid input Examples largestDigit(12345) ---> 5 largest Digit(7394) ---> 9 largestDigit(-52) ---> 5 largestDigit(1.23) --->-1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Organizing Information Digital And Information Literacy

Authors: Greg Roza

1st Edition

1448805929, 978-1448805921

More Books

Students also viewed these Databases questions

Question

Distinguish between filtering and interpreting. (Objective 2)

Answered: 1 week ago