help! writing afunction for isprime

1 visualizzazione (ultimi 30 giorni)
mustafa aladhami
mustafa aladhami il 23 Set 2016
Commentato: George il 24 Set 2016
i'm not sure how to write this since i'm new to matlab!
Write a function that receives a number n and determine if it is a prime number (output 1) or not (output 0). You can not use the ‘isprime’ function.

Risposte (1)

George
George il 24 Set 2016
Do you know how to test whether a number is prime? Here is one way you can start:
  1. Generate numbers between 2:(n/2)
  2. Test if n is divisible by any of those numbers (eg mod())
  3. Return appropriately based on #2.
  2 Commenti
Walter Roberson
Walter Roberson il 24 Set 2016
You do not need to go as far as n/2, you can stop at sqrt() of the number
George
George il 24 Set 2016
That's true.

Accedi per commentare.

Categorie

Scopri di più su Downloads in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by