Hello!
I have an assignment in school to find prime numbers.
In my function i'm supposed to find the prime numbers and delete the numbers that are not a prime.
The application is not complete so don't worry about my return value etc.
I have looked up how other people have done their deletion of an element but I cannot seem to get it to work.
Any help would be nice, thank you!
Code:
int checkForPrime(int* a, int num){
int c = 0, j = 0;
for(int i = 0; i < num; i++){
for (j = 2; j <= (*a+i)/2; j++){
if(((*a+i) % j) == 0)
break;
}
if(*(a+i) > 1 && !(j<= (*a+i)/2)){
c++;
//printf("yes");
}
else{
//I want to delete the number that comes here,
//Will always know that *(a+i) is the correct number to delete.
}
printf("%d ", *(a+i));
}
return c;
}
int main()
{
int number[100];
int counter;
int result;
printf("Numbers to check: ");
scanf("%d", &counter);
// number = (int*)malloc(num*sizeof(int));
for(int i = 0; i < counter; i++){
printf("number %d: ",i+1);
scanf("%d", number+i);
}
result = checkForPrime(number, counter);
//printf("%d", result);
return 0;
}