add primary code

This commit is contained in:
2025-04-04 15:57:50 +02:00
parent 5bc7fc22bc
commit 7b00930f69
5 changed files with 35 additions and 0 deletions

BIN
primtallYey/hei1 Executable file

Binary file not shown.

BIN
primtallYey/hei2 Executable file

Binary file not shown.

BIN
primtallYey/hei3 Executable file

Binary file not shown.

35
primtallYey/p.c Normal file
View File

@@ -0,0 +1,35 @@
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
bool checkPrime(int p, int *pptr){
int sqrt_p = sqrt(p);
for(int i = 0; i < sqrt_p; i++){
if(p % *(pptr+i) == 0){return false;}
}
return true;
}
int main(){
double max = pow(10,7);
int pi_max = (int)(ceil(1.1*(max/log(max))));
int primes[pi_max];
primes[0] = 2;
int *pptr = &primes[0];
int count = 1;
//calculate primes
for(int c = 3; c <= max; c+=2){
if(checkPrime(c, pptr)){
primes[count] = c;
count++;
}
}
//print primes
printf("The set of all primes below %d is: ", (int)max);
for (int i = 0; i < count; i++){
printf("%d ", primes[i]);
}
return 0;
}

BIN
primtallYey/p.o Normal file

Binary file not shown.