Question

Written in expanded form, the usual factorial func
0 0
Add a comment Improve this question Transcribed image text
Answer #1

In the following, the required code is attached along with sample output for the given data. Coding and Output screensho octa

function [val] = skipfact(n,k)
   val = 1; % for n = 0, val = 1. Init cond
   if floor(n) == n && ~isinf(n) %Checking if +ve integer but not infinity
       for i = n:-1*k:1 %check until 1
           val = val * i;
       end
   end
   if n < 0 %negative
       val = -2;
   end
   if floor(n) ~= n || isinf(n) %Not positive integers
       val = -1;
   end
end

skipfact(7,1) %calling for given sample data
skipfact(23,3)
skipfact(193,37)
skipfact(9.2,3)
skipfact(-9.2,3)
skipfact(-8,3)

Add a comment
Know the answer?
Add Answer to:
Written in expanded form, the usual factorial function is n! = n middot (n - 1)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT