Sunday , December 11 2016
Home / C / C Program to count prime numbers in given range

C Program to count prime numbers in given range

This is the program to count total number of Prime numbers with in 1 to specified range 

Output

These are the some sample output which you can check using this programs.
1 10 4
2 100 25
3 1,000 168
4 10,000 1,229
5 100,000 9,592
6 1,000,000 78,498
7 10,000,000 664,579
8 100,000,000 5,761,455
9 1,000,000,000 50,847,534
tags: Prime Numbers, Program to find total number of prime numbers
Also See:   C program for string matching least time

Check Also

Hide Mouse Pointer C Program

How to Hide a Mouse Pointer Program in C : This program will show and hide ...

2 comments

  1. this program gives the output quite close but not the actual wright answer. I am wildly assuming that this is the code for the legendary Riemann Zeta Function.

    Anyway but the actual code will be :-

    #include
    #include
    void main()
    {

    int i,j,k,count=0,l,r;
    clrscr();

    printf(“Enter the lower limit. “);
    scanf(“%d”,&k);
    printf(“Enter the upper limit. “);
    scanf(“%d”,&l);
    printf(“\n”);

    for (i=k ; i<=l ; i++)
    {
    for (j=2 ; j<i ; j++)
    {

    r=i%j;

    if (r==0)
    break;

    }

    printf("\n");

    if (r!=0)
    {
    printf("%d is Prime\n",i);
    count++;
    }
    else

    printf("%d is Composite\n",i);

    }

    printf("\n\n Total no. of Primes is %d",count);
    printf("\n Total no. of Composites is %d",l-k+1-count);

    getch();
    }

    Enter the lower limit. 2
    Enter the upper limit. 10

    the output will be—

    2 is Prime

    3 is Prime

    4 is Composite

    5 is Prime

    6 is Composite

    7 is Prime

    8 is Composite

    9 is Composite

    10 is Composite

    Total no. of Primes is 4
    Total no. of Composites is 5

  2. this program gives the output quite close but not the actual wright answer. I am wildly assuming that this is the code for the legendary Riemann Zeta Function.

    Anyway but the actual code will be :-

    #include
    #include
    void main()
    {

    int i,j,k,count=0,l,r;
    clrscr();

    printf(“Enter the lower limit. “);
    scanf(“%d”,&k);
    printf(“Enter the upper limit. “);
    scanf(“%d”,&l);
    printf(“\n”);

    for (i=k ; i<=l ; i++)
    {
    for (j=2 ; j<i ; j++)
    {

    r=i%j;

    if (r==0)
    break;

    }

    printf("\n");

    if (r!=0)
    {
    printf("%d is Prime\n",i);
    count++;
    }
    else

    printf("%d is Composite\n",i);

    }

    printf("\n\n Total no. of Primes is %d",count);
    printf("\n Total no. of Composites is %d",l-k+1-count);

    getch();
    }

    Enter the lower limit. 2
    Enter the upper limit. 10

    the output will be—

    2 is Prime

    3 is Prime

    4 is Composite

    5 is Prime

    6 is Composite

    7 is Prime

    8 is Composite

    9 is Composite

    10 is Composite

    Total no. of Primes is 4
    Total no. of Composites is 5

Leave a Reply

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

Preventing spam * Time limit is exhausted. Please reload the CAPTCHA.