lcpri.c
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...
AI
AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Source Code
/*
Save this file as lcpri.c
*/
#include <stdio.h>
#include <stdlib.h>
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;
}
Original Comments (3)
Recovered from Wayback Machine