0% found this document useful (0 votes)
5 views

Sample Algorithm

The document outlines an algorithm to print all prime numbers within a user-defined range. It involves taking input for the start and end limits, checking each number for primality by testing divisibility from 2 to the square root of the number. If a number is determined to be prime, it is printed; the process continues for all numbers in the specified range.

Uploaded by

GAGANDEEP SINGH
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Sample Algorithm

The document outlines an algorithm to print all prime numbers within a user-defined range. It involves taking input for the start and end limits, checking each number for primality by testing divisibility from 2 to the square root of the number. If a number is determined to be prime, it is printed; the process continues for all numbers in the specified range.

Uploaded by

GAGANDEEP SINGH
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Example Algorithm: Prime Numbers in a Given Range

Problem Statement:

Write an algorithm to print all prime numbers between two numbers (start and end) provided
by the user.

Algorithm: Print Prime Numbers in a Range

1. Start

2. Take input from the user:

start → lower limit of range


end → upper limit of range

3. Loop through all numbers from start to end

4. For each number n :

If n is less than 2, skip it (since 1 and 0 are not prime)


Initialize a flag is_prime = True
Check divisibility from 2 to sqrt(n) :
If n is divisible by any number in this range, set is_prime = False and
break the loop

5. If is_prime remains True , print the number n as prime

6. Repeat for all numbers in the given range

7. End

You might also like