VOOZH about

URL: https://www.geeksforgeeks.org/c/c-program-to-display-prime-numbers-between-two-intervals-using-functions/

⇱ C Program to Display Prime Numbers Between Two Intervals Using Functions - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C Program to Display Prime Numbers Between Two Intervals Using Functions

Last Updated : 8 Jun, 2023

Prime numbers have only 2 factors, 1 and themselves. For example, 2,3, 5, 7, 9,... are the first 5 prime numbers. Here we will build a C program to display prime numbers between two intervals using functions using 2 approaches, for loop and while loop. 

👁 Prime Numbers between two intervals
 

Example

Input: num1 = 2, num2 = 10

Output: Prime numbers between 2 and 10 are: 2 3 5 7 

Explanation: The prime numbers between the given intervals 2(starting limit) and 10(ending limit) are 2 3 5 and 7

Using For Loop

Below is the C program to display prime numbers between two intervals using functions and for loop:


Output
Prime numbers between 2 and 10 are: 2 3 5 7 

Using While Loop

Below is the C program to display prime numbers between two intervals using functions and while loop:


Output
The prime numbers between 2 to 10 are: 2, 3, 5, 7, 
Comment
Article Tags: