Monday , September 25 2017
Home / c-program / C Program – Print prime numbers between two numbers

C Program – Print prime numbers between two numbers

C Program to print the prime numbers between two numbers.

Prime numbers between two numbers :


#include<stdio.h> 
#include<math.h> 
void printPrimes(int num1,int num2); 
int isPrimeNumber(int n); 
int main(void) 
{ 
    int num1,num2; 
    printf("Enter any two numbers : "); 
    scanf("%d%d",&num1,&num2); 
    printf("The prime numbers between %d and %d are : ",num1,num2); 
    printPrimes(num1,num2); 
    return 0; 
} 
void printPrimes(int num1, int num2) 
{ 
    int i; 
    for(i=num1; i<=num2; i++) 
           if(isPrimeNumber(i)) 
            printf("%d ",i); 
} 
int isPrimeNumber(int n) 
{ 
    int i; 
    for(i=2; i<=sqrt(n); i++)     
        if(n%i==0) 
            return 0; 
    return 1; 
}

Enter any two numbers :
1
20
The prime numbers between 1 and 20 are : 1 2 3 5 7 11 13 17 19

Enter any two numbers :

1
10
The prime numbers between 1 and 10 are : 1 2 3 5 7

Happy Learning 🙂

About chandrashekhar

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Recommended

C Program to add elements of an array

How to add elements in an array using C Program. Add elements of an Array …

Leave a Reply

Your email address will not be published. Required fields are marked *