Close Menu
Fsc Online | Online Notes, Educational News & Latest Government Job UpdatesFsc Online | Online Notes, Educational News & Latest Government Job Updates
  • Home
  • Notes
    • Online Courses
      • 12th Class
      • 11th Class
      • 10th Class
      • 9th Class
  • Jobs
    • PPSC Jobs
    • SPSC Jobs
    • Punjab Police Jobs
  • Education News
  • E-Books
    • Punjab Text Book (PTB)
  • Model Papers
  • Results
  • Admissions
  • Colleges
  • More
    • Paper Schemes
    • Date Sheets
    • Guess Papers
    • Roll No Slips
Facebook X (Twitter)
Trending
  • NADRA Islamabad Announced Latest April Jobs 2024
  • TEVTA Sargodha Announced Instructor / Clerk Jobs 2024
  • BPSC Announced Latest Jobs Through Advertisement no. 03/2024
  • All Subjects 12th Class Paper Scheme 2024 | Punjab Board
  • 12th Class Computer Science Paper Scheme 2024 Punjab Board
  • 9th Class Pakistan Studies Guess Papers 2024 Punjab Board
  • 12th Class Biology Paper Pairing Scheme 2024 Punjab Board
  • Physics 12th Class Paper Scheme 2024 Punjab Board
Fsc Online | Online Notes, Educational News & Latest Government Job UpdatesFsc Online | Online Notes, Educational News & Latest Government Job Updates
  • Home
  • Notes
    • Online Courses
      • 12th Class
      • 11th Class
      • 10th Class
      • 9th Class
  • Jobs
    • PPSC Jobs
    • SPSC Jobs
    • Punjab Police Jobs
  • Education News
  • E-Books
    • Punjab Text Book (PTB)
  • Model Papers
  • Results
  • Admissions
  • Colleges
  • More
    • Paper Schemes
    • Date Sheets
    • Guess Papers
    • Roll No Slips
Fsc Online | Online Notes, Educational News & Latest Government Job UpdatesFsc Online | Online Notes, Educational News & Latest Government Job Updates
Home » Computer Science » C Language » C Programs » [C/C++] Program to Find Prime Number Between Given Range
C Language

[C/C++] Program to Find Prime Number Between Given Range

September 26, 2015Updated:September 13, 20182 Comments2 Mins Read
WhatsApp Facebook Twitter Pinterest LinkedIn Tumblr Email

What is a Prime Number?
” A Natural number greater than 1 which has only two divisor 1 and itself is called prime number “.
For Example:
5 is prime, because it has only two divisors 1 and itself.

C Code

#include <stdio.h>
#include <math.h>
#include <conio.h>

void main()
{
 int startNum,endNum;
 int total=0;
 printf("Enter Number START of Range: ");
 scanf("%d", startNum);
 printf("Enter Number END of Range: ");
 scanf("%d", endNum);
 for(int i=startNum;i<=endNum;i++)
 {
 int count=0;
 for(int j=2;j<=sqrt(i);j++)
 {
 if(i%j==0)
 { count++; break; }
 
 }
 if(count==0 && i>1)
 { 
 total++;
 printf("Prime Number -> %d\n", i);
 }
 }

 printf("Total Prime Number Between %d to %d = %d\n", startNum, endNum,total);
 
 getch();
}

C++ Code

#include<iostream>
#include<math.h>

using namespace std;

int main()
{
 int startNum,endNum;
 int total=0;
 cout<<"Enter Number START of Range: ";
 cin>>startNum;
 cout<<"Enter Number END of Range: ";
 cin>>endNum;
 for(int i=startNum;i<=endNum;i++)
 {
 int count=0;
 for(int j=2;j<=sqrt(i);j++)
 {
 if(i%j==0)
 { count++; break; }
 
 }
 if(count==0 && i>1)
 { 
 total++;
 cout << "Prime Number -> " << i << endl;
 }
 }

 cout<<"Total Prime Number Between " << startNum 
 << " to " << endNum << " = " << total << endl;
 
 return 0;
}

Output:

program-to-find-prime-number-in-given-range

Other Related Search Terms

  1. Code For Prime Number In C++
  2. Code For Prime Number In C
  3. C++ Programs to find Prime number
  4. C Programs to find Prime number
  5. Find all Prime numbers between 1 to 100

c programs computer science 2nd year cpp programs Online Course
Share. WhatsApp Facebook Twitter Pinterest LinkedIn Tumblr Email
Khurram Farooq
  • Website
  • Facebook
  • X (Twitter)

I'm a full-stack developer, specializing in the PHP, JS, Wordpress, MEAN Stack, MERN Stack & Django. I hold a high standard of quality in everything that I do.

Related Posts

How to do Exponents in Java – 3 Different Methods

January 12, 2020

Different Types of Processors And Their Features

January 12, 2020

Biology 1st Year Guess Paper 2018 Punjab Board

May 28, 2018

2 Comments

  1. Arslan on April 2, 2016 4:23 pm

    #include
    #include
    void main(void){
    clrscr();
    int flag=0,num;
    printf(“Enter range = “);
    scanf(“%d”,&num);
    for(int i=2;i<=num;i++)
    {
    for(int j=2;j<=i/2;j++)
    {
    if(i%j==0){
    flag++;break;}
    }
    if(flag==0){
    printf(" %d ",i);
    }
    flag=0;

    }
    getch();
    }

    Reply
  2. Arslan Majeed on May 3, 2017 9:49 am

    #include
    #include
    main ()
    {
    int up,low,i,j,sum,flag,pnum;
    pnum=0;
    sum=0;
    flag=0;
    cout<>low;
    cout<>up;
    //for inputting the vlues again and again till user input all the values true..
    while(lowup)
    {
    if(low<2)
    {
    cout<<"THE lower value must be grater then 1\n";
    cout<>low;
    cout<>up;
    }
    else
    {
    cout<<"THe Uper limit must be grater than the lower\n";
    cout<>low;
    cout<>up;
    }
    }
    cout<<"\n THe prime numbers B/W the Range are: \n\n ";
    //findin the prime number…
    for(i=low; i<=up; i++)
    {
    for(j=2; j<=i/2; j++)
    {
    if(i%j==0)
    {
    flag++;
    break;
    }
    }
    if(flag==0)
    {
    cout<<i<<"\t";
    //counting the total prime numbers within the range…
    pnum++;
    // calculatting the sum of all prime numbers within the range..
    sum += i;
    }
    flag=0;
    }
    cout<<"\n\n\nTotal number of Prime number B/W the range are: "<<pnum;
    cout<<"\n\n\nTHe sum of all Prime numbers B/W the range is: "<<sum;
    getche();
    }

    Reply
Leave A Reply Cancel Reply

SEARCH
ADVERTISEMENT
STAY WITH US
  • Facebook
  • Twitter
  • Instagram
LATEST JOBS

NADRA Islamabad Announced Latest April Jobs 2024

April 4, 2024

TEVTA Sargodha Announced Instructor / Clerk Jobs 2024

April 4, 2024

BPSC Announced Latest Jobs Through Advertisement no. 03/2024

April 4, 2024
LATEST NOTES

All Subjects 12th Class Paper Scheme 2024 | Punjab Board

April 4, 2024

12th Class Computer Science Paper Scheme 2024 Punjab Board

April 4, 2024

9th Class Pakistan Studies Guess Papers 2024 Punjab Board

April 4, 2024
RECENT POSTS

NADRA Islamabad Announced Latest April Jobs 2024

April 4, 2024

TEVTA Sargodha Announced Instructor / Clerk Jobs 2024

April 4, 2024

BPSC Announced Latest Jobs Through Advertisement no. 03/2024

April 4, 2024

All Subjects 12th Class Paper Scheme 2024 | Punjab Board

April 4, 2024
TRENDING THIS WEEK

BISE Lahore Board 11th Class Revised Enrollment Schedule 2023-25

October 4, 2023

PEC 6th Class SBA (All-Subjects) Model papers 2023

December 14, 2022

Urdu 9th Class Model Papers 2024 [Download PDF]

October 28, 2022
ABOUT US
ABOUT US

Notes, Guess Papers, Old Papers, Jobs, Admissions, Results, Datasheets and everything else that falls into the wide world of education & careers. For any assist and query please contact us.

Home · About Us · Team · Contact · Advertise · DMCA Policy · Cookies Policy · Privacy Policy
© 2013-2026 Powered By FScOnline - Made with ♥ for the students of Pakistan.

Type above and press Enter to search. Press Esc to cancel.

Go to mobile version
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.