Primes whose first and last number is 3: Difference between revisions

add C
(add C)
Line 121:
Primes beginning and ending with '3' 1-999999: 2251
</pre>
 
=={{header|C}}==
{{trans|FreeBASIC}}
<lang c>#include<stdio.h>
#include<stdlib.h>
#include<math.h>
 
int isprime( int p ) {
int i;
if(p==2) return 1;
if(!(p%2)) return 0;
for(i=3; i*i<=p; i+=2) {
if(!(p%i)) return 0;
}
return 1;
}
 
int main(void) {
int np = 1, d, i, n;
printf( "3 " );
for(d=1; d<6; d++) {
for(i=3; i<pow(10,d)-1; i+=10) {
n = i + 3*pow(10,d);
if(isprime(n)) {
++np;
if(n<4009) {
printf("%d ",n);
if(!(np%10)) printf("\n");
}
}
}
}
printf( "\n\nThere were %d primes of the form 3x3 below one million.\n", np );
return 0;
}</lang>
{{out}}<pre>
3 313 353 373 383 3023 3083 3163 3203 3253
3313 3323 3343 3373 3413 3433 3463 3533 3583 3593
3613 3623 3643 3673 3733 3793 3803 3823 3833 3853
3863 3923 3943
 
There were 2251 primes of the form 3x3 below one million.</pre>
 
=={{header|F_Sharp|F#}}==
Line 132 ⟶ 174:
3 313 353 373 383 3023 3083 3163 3203 3253 3313 3323 3343 3373 3413 3433 3463 3533 3583 3593 3613 3623 3643 3673 3733 3793 3803 3823 3833 3853 3863 3923 3943
</pre>
 
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
781

edits