Write a recursive function named largestDigit that accepts an integer parameter and returns the largest digit value that appears in that integer. Your function should work for both positive and...


Write a recursive function named largestDigit that accepts an integer parameter<br>and returns the largest digit value that appears in that integer. Your function should<br>work for both positive and negative numbers. If a number contains only a single digit,<br>that digit's value is by definition the largest.<br>You must not use any loops; you also cannot use the string type or any library<br>functions. Your function must be recursive.<br>Complete the following file:<br>largestDigit.cpp<br>2 // You may use this helper function<br>3 int max(int a, int b) { return a < b ? b : a; }<br>4<br>5 int largestDigit(int n)<br>if((n<0) && (n/10<br>if(n<0) n =<br>0)) return n;<br>8<br>-n;<br>static int maxi<br>9<br>n%10;<br>0) return maxi;<br>maxi = max(maxi, n%10);<br>return largestDigit(n/10);<br>=<br>10<br>if((n/10)<br>11<br>12<br>13<br>14<br>15<br>16 }<br>Submit<br>Calling with Arguments<br>Name<br>Arguments Actual Expected<br>pass largestDigit 135725<br>7<br>7<br>pass largestDigit 111211<br>2<br>2<br>fail<br>largestDigit 100000<br>1<br>pass largestDigit 4530021<br>5<br>pass largestDigit 7639852<br>fail<br>largestDigit 76352<br>6<br>pass largestDigit 666555444<br>6<br>6<br>pass largestDigit 12424224<br>4<br>pass largestDigit 1242526<br>6<br>pass largestDigit o<br>670O<br>

Extracted text: Write a recursive function named largestDigit that accepts an integer parameter and returns the largest digit value that appears in that integer. Your function should work for both positive and negative numbers. If a number contains only a single digit, that digit's value is by definition the largest. You must not use any loops; you also cannot use the string type or any library functions. Your function must be recursive. Complete the following file: largestDigit.cpp 2 // You may use this helper function 3 int max(int a, int b) { return a < b="" b="" :="" a;="" }="" 4="" 5="" int="" largestdigit(int="" n)=""><0) &&="" (n/10=""><0) n="0))" return="" n;="" 8="" -n;="" static="" int="" maxi="" 9="" n%10;="" 0)="" return="" maxi;="" maxi="max(maxi," n%10);="" return="" largestdigit(n/10);="10" if((n/10)="" 11="" 12="" 13="" 14="" 15="" 16="" }="" submit="" calling="" with="" arguments="" name="" arguments="" actual="" expected="" pass="" largestdigit="" 135725="" 7="" 7="" pass="" largestdigit="" 111211="" 2="" 2="" fail="" largestdigit="" 100000="" 1="" pass="" largestdigit="" 4530021="" 5="" pass="" largestdigit="" 7639852="" fail="" largestdigit="" 76352="" 6="" pass="" largestdigit="" 666555444="" 6="" 6="" pass="" largestdigit="" 12424224="" 4="" pass="" largestdigit="" 1242526="" 6="" pass="" largestdigit="" o="">

Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here