- Related Questions & Answers
- Average numbers in array in C Programming
- C Program for Tower of Hanoi
- C++ Program for Dijkstra’s shortest path algorithm?
- C/C++ Program for nth Catalan Number?
- C Program to Multiply two Floating Point Numbers?
- C program to find the length of a string?
- C Program to Check if all digits of a number divide it
- C Program to Check if a Given String is a Palindrome?
- Write a program to Delete a Tree in C programming
- Write a C program to print “ Tutorials Point ” without using a semicolon
- Super Prime in c programming
- Sum of the numbers up to N that are divisible by 2 or 5 in c programming
- Sum of the nodes of a Singly Linked List in C Program
- Sum of first n natural numbers in C Program
- C Program for simple interest?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this article, we will learn about the solution to the problem statement given below.

**Problem statement **− We are given an interval we need to compute all the prime numbers in a given range

Here we will be discussing a brute-force approach to get the solution i.e. the basic definition of a prime number. Prime numbers are the number which has 1 and itself as a factor and rests all the numbers are not its factors.

Each time the condition of a prime number is evaluated to be true computation is performed.

Now let’s observe the concept in the implementation below−

start = 1 end = 37 for val in range(start, end + 1): # If num is divisible by any number # between 2 and val, it is not prime if val > 1: for n in range(2, val): if (val % n) == 0: break else: print(val)

2 3 5 7 11 13 17 19 23 29 31 37

All the variables are declared in the local scope and their references are seen in the figure above.

In this article, we have learned about how we can print all the prime numbers in an interval

Advertisements