# lcpri.c

Email
 Submitted on: 1/1/2015 8:14:00 AM By: Luke (from psc cd) Level: Beginner User Rating: By 3 Users Compatibility: C Views: 1198

How many prime numbers are there between 1 and X? You just have to choose X and this program will do the rest. Click Luke to go to my Web Page: other source code available...

code:
Can't Copy and Paste this?
 ``` //************************************** // Name: lcpri.c // Description:How many prime numbers are there between 1 and X? You just have to choose X and this program will do the rest. Click Luke to go to my Web Page: other source code available... // By: Luke (from psc cd) // // Inputs:an integer number // // Returns:the number of prime numbers lower than X //************************************** /* Save this file as lcpri.c */ #include #include int main() { ldiv_t dividi; int n, totprimi, primo; int cont1, cont2; printf("\n\tEnter an integer (>= 1): "); scanf("%d", &n); if (n < 1) { printf("\n\t...I said >= 1...bye!\n"); return(-1); } totprimi = 0; for(cont1 = 1; cont1 < n; cont1++) { primo = 1; for(cont2 = 2; cont2 <= (cont1 / 2); cont2++) { dividi = ldiv(cont1, cont2); if (dividi.rem == 0) { primo = 0; break; } } if (primo) ++totprimi; } printf("\n\tThere are %d prime numbers lower than %d\n", totprimi, n); return 0; } ```

Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)