For integers X and Y received from the user (assuming X < Y), write the program that adds all Germain prime numbers in the range of X to Y to an array and prints the elements in this array on the screen. Germain prime numbers are primes such that the number 2p + 1 is also prime. An additional string will not be used in this question. Otherwise, it will be evaluated as 0.
Sample:
Enter X and Y: 2 15
Germain Prime Numbers in the Range: 2-3-5-11
I have a question like that. I wrote a program but it was printing some wrong numbers, too. However, it doesn't print anything now
Here is my code:
#include <stdio.h>
#include <stdlib.h>
int main() {
int x, y, i, j, k, counter = 0, counter2 = 0;
printf("Please enter x and y values:\n\a");
scanf("%d %d", &x, &y);
for (i = x; i <= y; i++) {
for (j = 1; j <= i; j++) {
if (i % j == 0) {
counter++;
}
}
if (counter == 2) {
for (k = 1; k <= 2 * i + 1; k++) {
if ((2 * i + 1) % k == 0) {
counter2++;
}
if (counter2 == 2) {
printf("%d is a germain prime number", i);
}
}
}
counter = 0;
}
return 0;
}
Can someone tell me where my mistake is?
Edit: I shouldn't use the functions created by user