Display Prime Numbers Between Two Intervals

prime number range in c

#include<stdio.h>
#include<conio.h>
int CheckPrimeNumber(int number);
void CheckPrimeNumberRange();
void main()
{
	CheckPrimeNumberRange();
	getch();
}
void CheckPrimeNumberRange()
{
	int min,max;
	printf("Enter your min number \n");
	scanf("%d",&min);
	printf("Enter you max number\n");
	scanf("%d",&max);
	printf("Prime Numbers are between %d and %d\n",min,max);
	for(int i=min;i<=max;i++)
	{
		if(CheckPrimeNumber(i)>0)
		{
			printf("%d ",i);
		}
	}
}
int CheckPrimeNumber(int number)
{
	int count=0;
	for(int i=2;i<number;i++)
	{
		if(number%i==0)
		{
			count=1;
			break;
		}
	}
	if(count==0)
	{
		return number;
	}
	else
	{
		return 0;
	}
}

Output

Enter your min number
10
Enter you max number
100
Prime Numbers are between 10 and 100
11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

prime number range in c++

#include<iostream>
#include<conio.h>
using namespace std;
class PrimeNumber
{
public:
int CheckPrimeNumber(int number)
{
	int count=0;
	for(int i=2;i<number;i++)
	{
		if(number%i==0)
		{
			count=1;
			break;
		}
	}
	if(count==0)
	{
		return number;
	}
	else
	{
		return 0;
	}
}
public:
void CheckPrimeNumberRange()
{
	int min,max;
	cout<<"Enter your min number \n";
	cin>>min;
	cout<<"Enter you max number\n";
	cin>>max;
	cout<<"Prime Numbers are between "<<min<<" and "<<max<<endl;
	for(int i=min;i<=max;i++)
	{
		if(CheckPrimeNumber(i)>0)
		{
			printf("%d ",i);
		}
	}
}

};
void main()
{
    PrimeNumber primeNumber;
	primeNumber.CheckPrimeNumberRange();
	
	getch();
}

Output

Enter your min number
1
Enter you max number
100
Prime Numbers are between 1 and 100
1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 9

prime number range in c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PrimeNumberProject
{
    class PrimeNumber
    {
       public int CheckPrimeNumber(int number)
        {
            int count = 0;
            for (int i = 2; i < number; i++)
            {
                if (number % i == 0)
                {
                    count = 1;
                    break;
                }
            }
            if (count == 0)
            {
                return number;
            }
            else
            {
                return 0;
            }
        }
       public void CheckPrimeNumberRange()
       {
           int min, max;
           Console.WriteLine("Enter your min number");
           min = Convert.ToInt32(Console.ReadLine());
           Console.WriteLine("Enter you max number");
           max = Convert.ToInt32(Console.ReadLine());
           Console.WriteLine("Prime Numbers are between "+ min + " and " + max);
           for (int i = min; i <= max; i++)
           {
               if (CheckPrimeNumber(i) > 0)
               {
                   Console.Write(i+ " ");
               }
           }
       }
        static void Main(string[] args)
        {
            PrimeNumber pn = new PrimeNumber();
            pn.CheckPrimeNumberRange();
            Console.ReadLine();
        }
    }
}

Output

Enter your min number
50
Enter you max number
100
Prime Numbers are between 50 and 100
53 59 61 67 71 73 79 83 89 97

prime number range in java

import java.util.*;
class PrimeNumber
{
    public int CheckPrimeNumber(int number)
    {
        int count = 0;
        for (int i = 2; i < number; i++)
        {
            if (number % i == 0)
            {
                count = 1;
                break;
            }
        }
        if (count == 0)
        {
            return number;
        }
        else
        {
            return 0;
        }
    }
	public void CheckPrimeNumberRange()
    {
        int min, max;
        Scanner obj=new Scanner(System.in);
        System.out.println("Enter your min number");
        min = obj.nextInt();
        System.out.println("Enter you max number");
        max = obj.nextInt();
        System.out.println("Prime Numbers are between "+ min + " and " + max);
        for (int i = min; i <= max; i++)
        {
            if (CheckPrimeNumber(i) > 0)
            {
            	System.out.print(i+ " ");
            }
        }
    }
}
class examples
{
public static void main(String[] args)
	{
     PrimeNumber primeNumber=new PrimeNumber();
     primeNumber.CheckPrimeNumberRange();
     }
}

Output

Enter your min number
1
Enter you max number
100
Prime Numbers are between 1 and 100
1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

Write a comment


Name Email Message