How to display all prime numbers between two number input by user?
Mostra commenti meno recenti
How to display all prime numbers between two number input by user?
Risposta accettata
Più risposte (3)
B.k Sumedha
il 23 Mag 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
il 23 Mag 2015
Modificato: Josaiah Ang
il 23 Mag 2015
Rashed Khan
il 28 Nov 2017
0 voti
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');
Categorie
Scopri di più su Nearest Neighbors in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!