C Program – Print prime numbers between two numbers

By | 2017-09-06T15:04:48+00:00 September 6th, 2017|c-program|0 Comments

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; 
}

[box type=”success” align=”alignleft” class=”” width=”100%”]

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

[/box]

Happy Learning 🙂

About the Author:

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+ ,

Leave A Comment