Problem 1 (Factorial with loops) Complete the function factorial_loop(num) that takes an integer num and returns the value of num!, i.e., num! = num * (num-1) * (num-2) * ... * 1. This function must use a loop (iteration) to compute the value of num!.
(in python)
def factorial_loop(num):
result = 1
for i in range(1, num + 1):
result *= i
return result
# Testing the function here. ignore/remove the code below if not required
n = int(input("Enter a positive integer: "))
print("Factorial of", n, "is", factorial_loop(n))
Problem 1 (Factorial with loops) Complete the function factorial_loop(num) that takes an integer num and returns...
C++ //Write prototype for function factorial that accepts an int num and returns an int /* WITH LOOP OF YOUR CHOICE: Write code for function factorial that accepts an int num and returns the num's factorial factorial(5); 1*2*3*4*5 returns 120 DON'T FORGET TO WRITE TEST CASE. */ //write includes statements //write using statements for cin and cout /* Use a do while loop to prompt the user for a number, call the factorial function, and display the number's factorial. Also,...
*** write in matlab *** use for loops
largestfactor_for Write a function that takes a positive integer greater than one and returns its largest factor (other than itseir). You must use a for loop to solve this problem. Do not use functions factor), primes(), and divisors() . Do not use while loops Do not use vectorized code. alargestfactor 105) 35
largestfactor_for Write a function that takes a positive integer greater than one and returns its largest factor (other than itseir)....
Create a function that takes a list and an integer v, and returns True if v is in the list (False otherwise). The function should be efficient and stop searching as soon as possible. •The main program must generate a very large list with random elements, call the function to search a value and display the result. Add in the function a variable Nsteps to count the number of steps used by the algorithm (number of times the loop is...
Java two dimensional arrays Create a method named curiousNumber that takes an integer named num as a parameter and returns a boolean. You can assume the num will be a positive integer. The curiousNumber method should determine whether num is a curious number. A curious number is a number that is equal to the sum of the factorial of each of its digits. For example, 145 is a curious number because 145 = 1! + 4! + 5!. sample: boolean...
Python Question? Write a function called reverse(user_list, num = -1) that takes a list and a number as parameters. The function returns a copy of the list with the first number of items reversed. Conditions: The number parameter must be a default argument. - If the default argument for number is given in the function call, only the first number of items are reversed. - If the default argument for number is not provided in the function call, then the...
1 write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple. Hint (can be done in one pass, you are not allowed to use built-on min and max functions.)max, min = find_max_min(my_list):2 write a Python function that takes in a list of integers (elements), and an integer number (num). The functions should count and return number of integers in elements greater than, less than, and equal to...
For Python: Complete the function sum_v2 that takes an integer n as input parameter and computes the sum of all odd integers between 5 and n (inclusively). Use FOR LOOP only and NO IF STATEMENTS.
PROBLEM 1 - FACTORIAL: Write a function prodN(n) taking as parameter an integer n. • If n is positive, the function returns the product of the first n natural numbers. • If n is zero, the function returns 1. • If n is negative or is not an integer, the function returns None. Remember to extensively test your program to make sure it works properly.
Write a method named factorial that accepts an integer n as a parameter and returns the factorial of n, or n!. A factorial of an integer is defined as the product of all integers from 1 through that integer inclusive. For example, the call of factorial(4) should return 1 2 3 4, or 24. The factorial of 0 and 1 are defined to be 1. You may assume that the value passed is non-negative and that its factorial can fit...
You must use C++ to answer this problem. "Write a recursive function squaresSum that takes a positive integer parameter, num, and returns the sum of squares of all integers from 1-num."