(Single Digit) Complete the definition of the following function:singleDigit :: Int -> Int singleDigit takes a positive integer, num, as input and returns a digit between 0 and 9 as the output. The output is computed as follows: sum all the digits in num to obtain a result; if this result is less than 10 then result is the answer; otherwise take the result and apply the same procedure (i.e. sum its digits and compute a result, and so on). Here is a sample run:*Main> singleDigit 37425 3 *Main> singleDigit 9876543 6 Here is how the above answers are computed by hand:singleDigit 37425 => 3+7+4+2+5 = 21 => 2+1 = 3 singleDigit 9876543 => 9+8+7+6+5+4+3 = 42 => 4+2 = 6

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter3: Assignment, Formatting, And Interactive Input
Section3.3: Using Mathematical Library Functions
Problem 1E
icon
Related questions
Question
  1. (Single Digit) Complete the definition of the following function:singleDigit :: Int -> Int singleDigit takes a positive integer, num, as input and returns a digit between 0 and 9 as the output. The output is computed as follows: sum all the digits in num to obtain a result; if this result is less than 10 then result is the answer; otherwise take the result and apply the same procedure (i.e. sum its digits and compute a result, and so on). Here is a sample run:*Main> singleDigit 37425 3 *Main> singleDigit 9876543 6 Here is how the above answers are computed by hand:singleDigit 37425 => 3+7+4+2+5 = 21 => 2+1 = 3 singleDigit 9876543 => 9+8+7+6+5+4+3 = 42 => 4+2 = 6
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Functions
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
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning