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

19 次查看(过去 30 天)
How to display all prime numbers between two number input by user?

采纳的回答

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

更多回答(3 个)

B.k Sumedha
B.k Sumedha 2015-5-23
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 2015-5-23
编辑:Josaiah Ang 2015-5-23
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 2017-11-28
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');

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by