Question

*** 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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

function a = largestfactor(N)
a = N;
for i = 2:N-1
if mod(N,i) == 0
a = i;
end
end
end

k = largestfactor(105)
k = largestfactor(12)
k = largestfactor(100)
k = largestfactor(90)

===========================
SEE OUTPUT
Your Code function a = largestFactorCN) for i 2:N-1 = if modCN,i)0 4 6 end 7 end 8 end 10 k largestFactor(105) 11 k largestFa

Thanks, PLEASE COMMENT if there is any concern.

Add a comment
Know the answer?
Add Answer to:
*** write in matlab *** use for loops largestfactor_for Write a function that takes a positive integer greater than one...
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
  • MATLAB Write a function called next_prime that takes a scalar positive integer input n. Use a whi...

    MATLAB Write a function called next_prime that takes a scalar positive integer input n. Use a while-loop to find and return k, the smallest prime number that is greater than n. Feel free to use the built-in isprime function (do not use nextprime). MATLAB

  • Prime numbers are the building blocks of all integers greater than 1. Any integer n >...

    Prime numbers are the building blocks of all integers greater than 1. Any integer n > 1 can be written as a unique product of primes i.e. n = p1 × p2 × ... × pm. Here, pi are primes such that p1 ≤ p2 ≤ ... ≤ pm. Take, for example, the number 18. It can be written as 18 = 2 × 3 × 3. 1. Write a Python function prime divisors(n) which accept an integer n and...

  • d printAllIntegers () Write a C++ program that defines and tests a function largest(....) that takes...

    d printAllIntegers () Write a C++ program that defines and tests a function largest(....) that takes as parame- ters any three integers and returns the largest of the three integers. Your output should have the same format and should work for any integers a user enters Desired output: Enter three integers: 6 15 8 The largest integer is: 15 7.3 Recursive Functions Write a program that uses a function sum(int) that takes as an argument a positive integer n and...

  • A positive integer greater than 1 is said to be prime if it has no divisors...

    A positive integer greater than 1 is said to be prime if it has no divisors other than 1 and itself. A positive integer greater than 1 is composite if it is not prime. Write a program that defines two functions is_prime() and list_primes(). is_prime() will determine if a number is prime. list_primes() will list all the prime numbers below itself other than 1. For example, the first five prime numbers are: 2, 3, 5, 7 and 11." THE PROGRAM...

  • Problem 1 (Factorial with loops) Complete the function factorial_loop(num) that takes an integer num and returns...

    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)

  • Write a function that takes a numerical vector and returns the sorted vector. To detect whether...

    Write a function that takes a numerical vector and returns the sorted vector. To detect whether a vector is sorted, use diff() and all() (or any()). So long as the vector is not sorted, pick two random positions from the vector and swap them. (in matlab program) You must use a while loop to solve this problem. Do not use for loops. Do not use sort(), min(), max(), sortrows(), unique() functions. >> v = sortbyrandomswaps( [39 25 91 71] )...

  • Using MATLAB write a function that takes a relatively small (less than 100 billion) positive integer...

    Using MATLAB write a function that takes a relatively small (less than 100 billion) positive integer input and outputs the prime factorization of that integer using as few built-in functions as possible. Explain the processes with comments.

  • need help with python ( no loops used please!) Write a recursive function named sum_digits that...

    need help with python ( no loops used please!) Write a recursive function named sum_digits that takes a given a non-negative integer N and returns the sum of its digits. Hint: Mod (%) by 10 gives you the rightmost digit (126 % 10 is 6), while doing integer division by 10 removes the rightmost digit (126/10 is 12). This function has to be recursive; you are not allowed to use loops to solve this problem! This function takes in one...

  • This code NEEDS TO BE DONE IN MATLAB!!!! Write a function that takes one input, an...

    This code NEEDS TO BE DONE IN MATLAB!!!! Write a function that takes one input, an integer number n, and returns a matrix that is nxn, where the value of each number is the distance from the upper-left to bottom-right diagonal. (Use while loops if you can!) Numbers below the diagonal should be negative, and numbers above the diagonal should be positive. For example, if your input was 5, your output would be: 0 1 2 3 4 -1 0...

  • This basic problem demonstrates the while-loop. (USE MATLAB) Write a Matlab function called steps that takes one scalar...

    This basic problem demonstrates the while-loop. (USE MATLAB) Write a Matlab function called steps that takes one scalar as an input argument and returns two scalars as output arguments. If it is called this way [n, d_left] = steps(d), then it sets n equal to the minimum number of steps required to move from a distance of one foot away from a wall to a distance less than d feet from the wall. The first step is 1/2 foot. If...

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