Question

Write a MATLAB program to determine the factorial value of an input integer between 1 and...

Write a MATLAB program to determine the factorial value of an input integer between 1 and 30. You may NOT use the built-in factorial function. You must implement it using a for loop. Display the result back to the user with 2 decimal places (yes, 2 decimal places). The result should follow the following format:   The factorial value is *.xx

Homework Answers

Answer #1

function result = facto(x)

%this function will generate factorial of a given number

%the output of the given input will be as follows:

% x(x-1)(x-2)(x-3).....(3)(2)(1)

% also if x = 0 then the value is 1 and also x is +integer

%If statement to check if the number is negative

if x<0

result = 'Negative numbers are not valid for factorial'

% else if the number is not an integer then we will convert the number to

% integer and find the value of the factorial

elseif int64(x) ~= x

fprintf('You have entered a number which is not an integer\n');

fprintf('Please enter a valid integer to find the factorial\n');

elseif x == 0

result = 1;

  

else

result = 1;

for i = 1:x

result = result*i;

end

end

Know the answer?
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
Similar Questions
Write a program in C++ coding that asks the user to input an integer between 25...
Write a program in C++ coding that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2...
Write a program that asks the user to input an integer between 25 and 50, inclusive....
Write a program that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2 relational expressions. You...
(8 marks) Write a program to ask user to input an integer and display the special...
Write a program to ask user to input an integer and display the special pattern accordingly. REQUIREMENTS The user input is always correct (input verification is not required). Your code must use loop statements (for, while or do-while). Your program should use only the following 3 output statements, one of EACH of the followings: System.out.print("-"); // print # System.out.print("+"); // print + System.out.println(); // print a newline Your code must work exactly like the following example (the text in bold...
Write a matlab program that takee a character (a-z) as an input and checks if that...
Write a matlab program that takee a character (a-z) as an input and checks if that is a vowel or not using switch statment? If the user inputs any other character, the program should display a proper error message.
Write a script (must be titled “NumIntF”) in MATLAB that calculates the integration of function f(x)=cos(x)...
Write a script (must be titled “NumIntF”) in MATLAB that calculates the integration of function f(x)=cos(x) . exp(sin x), Using numerical integration method. When the user runs the script, he/she is prompted to input the lower and upper limits for numerical integration, both in radians, and your program outputs the integration result. You can use built-in trigonometric functions and the exponential function, but you are not allowed to use any built-in function to do the integration. You must use a...
Be able to write Python programming of a factorial of an integer (given input parameters, output...
Be able to write Python programming of a factorial of an integer (given input parameters, output characteristics and expected output behavior, do not use internal python functions for factorials), recall for example that: 5! = 5 ∗ 4 ∗ 3 ∗ 2 ∗ 1 = 120 and to continue asking unless user says to stop NOT USING FACTORIAL FUNCTION
How can I write a function in MATLAB with an input of array1 and an output...
How can I write a function in MATLAB with an input of array1 and an output of maxValue (being the highest value in array 1) without calling the built in function in MATLAB. I ned to use a loop to accomplish this.
Write a C++ program that sets the maximum speed limit as a constant integer to be...
Write a C++ program that sets the maximum speed limit as a constant integer to be 120 Km/Hour. The program should read from the user an integer value representing the speed of a car. Use a nested if else to display a message based on the input speed: Speed < 10                      display      “Invalid speed” 10 <= Speed <= 120       display      “Speed is within limit” Speed > 120                    display      “Speed limit exceeded” At the end the program should display a message...
Write a program that asks the user of a positive integer value. The program should use...
Write a program that asks the user of a positive integer value. The program should use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1,2,3,4,…,50. using namespace std;
problem 1 Write a program that asks the user for an integer and then prints out...
problem 1 Write a program that asks the user for an integer and then prints out all its factors. For example, when the user enters 84, the program should print 2 2 3 7 Validate the input to make sure that it is not a character or a string using do loop. in c plus plus