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

#include<conio.h> long countprime(long a,long k) { long i; for(i=a;i>=2;i--) { if(k%i==0) return 0; } return 1; } void main() { long i,range; long count=1; double x; printf("Enter the range: "); scanf("%ld\n",&range); for(i=3;i<range;i++) { x=sqrt(i); count+=countprime(floor(x),i); } printf("\n Total number of prime numbers are %ld",count); getch(); }

## 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

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

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