How to display all prime numbers between two number input by user?

17 vues (au cours des 30 derniers jours)
How to display all prime numbers between two number input by user?

Réponse acceptée

Walter Roberson
Walter Roberson le 23 Mai 2015
n = firstnumber : secondnumber;
p = isprime(n);
n(p) %displays the primes

Plus de réponses (3)

B.k Sumedha
B.k Sumedha le 23 Mai 2015
clc
num1 =input('Enter num1 value ');
num2 =input('Enter num2 value ');
n = num1 : num2 ;
p = isprime(n);
n(p) %displays the primes
Well that was an gud answer from walter

Josaiah Ang
Josaiah Ang le 23 Mai 2015
Modifié(e) : Josaiah Ang le 23 Mai 2015
how do i go along with this set of code?
clc
num1 =input('Enter num1 value ');
num2 =input('Enter num2 value ');
n = firstnumber : secondnumber;
p = isprime(n);
n(p) %displays the primes

Rashed Khan
Rashed Khan le 28 Nov 2017
n=input('Type a number:'); j=0; fprintf('primes up to %d are:',n); for k=1:n if isprime(k)==1 fprintf('%d',k); j=j+1; else fprintf(''); end end fprintf('\n'); fprintf('Number of primes up to %d is %d',n,j); fprintf('\n');

Catégories

En savoir plus sur Function Creation dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by