Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This question asks you to compute the sum of the digits of a factorial of number. Note that, factorial of a is denoted by n

image text in transcribed
This question asks you to compute the sum of the digits of a factorial of number. Note that, factorial of a is denoted by n ! and compates to n(n1)321 n!=n(n1)(n2)+(3)(2)(1) For example, 10!=109321=3628800, and the sum of the digits in the number 10 t is 3+6+2+8+8+0+0=27 You are asked to write a function that takes an input number n and calculates the sam of all factorial digits. The first line of the function should read: function output = sum_factorial digits (n) The MATLAB code can build on following logic hint: - For a number n. the last digit is obtained as the remainder of dividing the number by 10 using command rem(n,10). Example: for n=7265, rem (n,10) will give us 5 . the second last digit is obtained by first dividing the number by 10 , taking the integer part of the quotient, and then finding its last digit as in the previots point. The MATL.AB command to get the second last digit is rem (f1 oor (n/10),10). Example: for n=7265, rem (f100r(n/10),10) will give us 6 . Likewise, the k-th last digit is given by dividing the number by 10k1, taking the integer part of the quotient, and finding the last digit in that. The MATLAB command to get the k-th last digit is rem (f100r(n/10(k1)),10). Examples for n=7265, to get the 42 last digit rem (fl00r(n/103),10) will give us 7 . - Hint \#2: Use a loop structure to loop through all digits that stops the process when the value of floor (n/10(k1) is 0 which means there are no more digits. - Hint \#3: Use factorial (n) function to calculate the value of factorial of n ( n !) As your submission include the following: - Complete M-file script. - Evaluated output of the function for following inputs: sum_factorial_digits (11) sum_factorial_digits (21)

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

Big Data Fundamentals Concepts, Drivers & Techniques

Authors: Thomas Erl, Wajid Khattak, Paul Buhler

1st Edition

0134291204, 9780134291208

More Books

Students also viewed these Databases questions

Question

What are the basic components of an online news release?

Answered: 1 week ago

Question

How are members held accountable for serving in the assigned roles?

Answered: 1 week ago

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago