Search This Blog

Tuesday, September 13, 2016

To accept two numbers from the user, display all prime numbers between these two numbers.

Question:

To accept two numbers from the user, display all prime numbers between these two numbers.


     Answer:


    clc
    num1 =input(' Enter your 1st number: ');
    num2 =input('\n Enter your 2st number: ');
    n = num1 : num2;
    p = isprime(n);
    n(p)    %displays the prime numbers

Output: I write down in command window


               Enter your 1st number: 1
                  Enter your 2st number: 100            ;then push enter

              ans =

  Columns 1 through 19
2     3     5     7    11    13    17    19    23    29    31    37    41    43    47    53    59    61    67
Columns 20 through 25
      71    73    79    83    89    97









No comments:

Post a Comment